Back to blog

Regex for File Organization: A Beginner's Guide to Smart Rules

Learn regex file organization rules from scratch. 10 copy-paste patterns for sorting screenshots, invoices, duplicates, and more with File Arbor.

March 2, 2026
File Arbor Team

What Is Regex and Why Does It Matter for File Organization?

You probably already know how to search for files by name. Type "invoice" into your file explorer, and you get every file with "invoice" in its name. Simple enough. But what if you want to find every invoice PDF that starts with "INV-" followed by a number? Or every screenshot regardless of whether it's called "Screenshot," "Screen Shot," or "Capture"? That is where regex comes in.

Regex (short for Regular Expression) is a pattern-matching language. Think of it as a search query on steroids. Instead of searching for exact text, you describe a pattern of text. A single regex pattern can match hundreds of different file names that share a common structure.

File Arbor uses regex in its Smart Rules feature. When Quick Rules are not enough for your specific needs, you can write a Custom Rule with a regex pattern. File Arbor then matches incoming files against that pattern and automatically moves them to the folder you specify. It is one of the most powerful ways to automate your file organization workflow.

You do not need a computer science degree to use regex. In this guide, we will walk through the fundamentals and give you 10 ready-to-use patterns that cover the most common file organization scenarios. By the end, you will be writing your own patterns with confidence.

If you are completely new to File Arbor, start with our Getting Started guide first, then come back here.

Regex Basics for File Names

Before jumping into practical patterns, let's build a solid foundation. Every regex concept below is something you will actually use when organizing files. We will keep the theory short and the examples concrete.

Literals: Matching Exact Text

The simplest regex is just plain text. The pattern invoice matches any file name that contains the word "invoice" anywhere in it.

Pattern:  invoice
Matches:  invoice-2026.pdf, my_invoice.docx, January-invoice-final.pdf

This is identical to a basic text search. The power of regex comes from everything else you can add on top of this.

Wildcards: The Dot and Star

The dot . matches any single character (letter, digit, space, symbol, anything except a newline). The combination .* matches any sequence of characters of any length, including an empty string.

Pattern:  report.*pdf
Matches:  report-2026.pdf, report_final.pdf, report.pdf

Here, .* bridges the gap between "report" and "pdf" regardless of what characters are in between.

Character Classes: Matching Specific Types

Square brackets let you define a set of characters to match at a single position:

  • [0-9] matches any single digit (0 through 9)
  • [a-z] matches any single lowercase letter
  • [A-Za-z] matches any letter, upper or lowercase
  • [aeiou] matches any vowel
Pattern:  IMG_[0-9][0-9][0-9][0-9]
Matches:  IMG_0001, IMG_2026, IMG_9999

You can also negate a class with ^ inside the brackets. [^0-9] matches anything that is not a digit.

Quantifiers: How Many Times?

Quantifiers control how many times the preceding element should repeat:

  • + means one or more times
  • * means zero or more times
  • ? means zero or one time (makes something optional)
  • {3} means exactly 3 times
  • {2,5} means between 2 and 5 times

Using quantifiers cleans up our earlier example significantly:

Pattern:  IMG_[0-9]{4}
Matches:  IMG_0001, IMG_2026, IMG_9999

The \d shorthand is equivalent to [0-9], so you can also write IMG_\d{4}. Similarly, \w matches any word character (letters, digits, and underscores).

Anchors: Start and End of the File Name

Anchors do not match a character. They match a position in the text:

  • ^ matches the start of the file name
  • $ matches the end of the file name

This is critical for file organization. Without anchors, invoice matches "my_invoice_backup.pdf" and "not-an-invoice-really.txt." With anchors, you gain precision:

Pattern:  ^invoice.*\.pdf$
Matches:  invoice-2026.pdf, invoice_march.pdf
Skips:    my_invoice.pdf, invoice.docx

Notice \.pdf$ at the end. The backslash escapes the dot so it matches a literal period rather than "any character." This is one of the most common things you will do in file name regex: matching file extensions precisely.

Groups: Combining Alternatives

Parentheses () group parts of a pattern together, and the pipe | means "or":

Pattern:  \.(jpg|png|gif)$
Matches:  photo.jpg, logo.png, animation.gif
Skips:    photo.bmp, document.pdf

This is how you match multiple file extensions in a single rule. Groups can also be combined with quantifiers. For example, (ab)+ matches "ab", "abab", "ababab", and so on.

Common File Extension Pattern

One pattern you will use repeatedly is matching a set of file extensions:

\.(jpg|jpeg|png|gif|webp|svg)$    # Image files
\.(mp4|avi|mkv|mov|wmv)$          # Video files
\.(doc|docx|pdf|txt|odt)$         # Document files
\.(mp3|wav|flac|aac|ogg)$         # Audio files

With these building blocks in your toolkit, you are ready to tackle real-world file organization patterns.

10 Practical Regex Patterns for File Organization

Here are ten copy-paste-ready regex patterns that solve the most common file clutter problems. Each one is explained so you understand how it works and can modify it for your own needs.

1. Screenshots

Every operating system names screenshots differently. macOS uses "Screenshot," older macOS versions used "Screen Shot," and Windows uses "Screenshot" as well. Some tools use "Capture."

^(Screenshot|Screen Shot|Capture).*\.(png|jpg)$

How it works: Matches file names that start with any of those three prefixes, followed by anything (the timestamp), ending with a .png or .jpg extension.

Suggested destination: Screenshots/

2. Duplicate Files

When you download the same file twice, your browser appends (1), (2), etc. Some systems use -copy instead.

.*\(\d+\)\.[a-zA-Z]+$

This catches files like report (1).pdf, image (3).png, and budget (12).xlsx. For the "-copy" variant, add an alternative:

.*(\(\d+\)|-copy)\.[a-zA-Z]+$

Suggested destination: Duplicates/ (review and delete periodically)

3. Invoices and Bills

Invoices often follow predictable naming patterns, especially when downloaded from accounting software or email attachments.

^(invoice|INV|facture|bill|receipt)[-_]?\d+.*\.pdf$

How it works: Starts with a common invoice keyword (case variations covered), optionally followed by a dash or underscore, then digits (the invoice number), then anything else, ending in .pdf. The term "facture" covers French-language invoices.

Suggested destination: Finance/Invoices/

4. Software Installers

Installers and package files pile up in your Downloads folder. This pattern catches them all.

.*\.(exe|msi|dmg|pkg|deb|rpm|appimage)$

How it works: Matches any file name ending with a common installer extension. No anchor at the start because installer names vary wildly.

Suggested destination: Installers/ (or just delete them after installation)

5. Photos by Camera Naming Convention

Digital cameras and phones name photos with a predictable prefix followed by a date or sequence number.

^(IMG|DSC|P|DSCN|DCIM|PXL)_?\d{8}.*\.(jpg|jpeg|raw|heic|cr2|nef)$

How it works: Matches names starting with common camera prefixes (IMG for phones, DSC/DSCN for Sony/Nikon, PXL for Pixel phones), an optional underscore, then 8 digits (typically a date like 20260302), followed by anything, ending with a photo extension.

Suggested destination: Photos/Unsorted/

6. Version-Numbered Files

Design mockups, drafts, and documents often include version numbers. These pile up fast.

.*[-_]v?\d+\.\d+.*

How it works: Matches any file with a version-like pattern somewhere in the name. The v? makes the "v" prefix optional, so it catches both design-v2.1.psd and spec-3.0-draft.pdf.

Suggested destination: Archives/Versioned/

7. Temporary Files

Temp files are created by applications and forgotten. They waste disk space and clutter your folders.

^~.*|.*\.tmp$|.*\.bak$|.*\.swp$|.*\.cache$

How it works: Uses the | operator to match several temp file indicators: files starting with a tilde (~), or ending with .tmp, .bak, .swp, or .cache.

Suggested destination: Trash/ or delete directly

8. Bank Statements

Banks typically export statements with the word "statement" followed by a year-month date pattern.

^(statement|releve|kontoauszug|extrait).*\d{4}[-_]\d{2}.*\.pdf$

How it works: Starts with a bank statement keyword (English, French, German), followed by anything, then a four-digit year, a separator, and a two-digit month, ending in .pdf. This catches files like statement_2026-03.pdf or releve_bancaire_2025_12.pdf.

Suggested destination: Finance/Bank Statements/

9. Project Files

If you name project files with a "project" or "PRJ" prefix, this pattern gathers them together.

^(project|PRJ|proj)[-_]\w+.*

How it works: Matches names starting with a project keyword, followed by a separator and one or more word characters (the project name or code). Files like project-alpha_v2.docx, PRJ_0042_spec.pdf, and proj-website-redesign.fig all match.

Suggested destination: Sort by project name into Projects/{project-name}/

10. Meeting Notes and Minutes

Meeting notes accumulate across every tool and format. This pattern catches the common naming conventions.

^(meeting|notes|minutes|standup|retro)[-_]\d{4}[-_]\d{2}[-_]\d{2}.*

How it works: Matches files starting with a meeting-related keyword, followed by a date in YYYY-MM-DD format (with either dashes or underscores as separators). Catches meeting-2026-03-02-product-review.docx, notes_2026_01_15.md, and similar.

Suggested destination: Documents/Meeting Notes/

How to Use Regex Patterns in File Arbor

Now that you have patterns ready, here is how to put them to work in File Arbor. The process takes about two minutes per rule.

Step 1: Open Smart Rules

Launch File Arbor and select the folder you want to organize (for example, your Downloads folder). Click the Rules tab in the sidebar, then click New Custom Rule.

Step 2: Enter Your Regex Pattern

In the Pattern field, paste or type your regex pattern. For example, to catch all screenshots:

^(Screenshot|Screen Shot|Capture).*\.(png|jpg)$

Make sure the Match Type is set to "Regex" rather than "Simple" (which only supports basic wildcards).

Step 3: Set the Destination

Choose where matched files should go. Click Browse and select the target folder, or type a path directly. You can use a subfolder that does not exist yet -- File Arbor will create it automatically.

Step 4: Test with Preview

Before enabling the rule, click the Preview button. File Arbor will scan the current folder and show you exactly which files match your pattern. This is your safety net. If unexpected files appear in the preview, refine your pattern before proceeding.

Step 5: Enable the Rule

Once the preview looks correct, toggle the rule to Enabled. If you have Auto Mode active (available with a Pro license), matched files will be moved automatically as they arrive. Otherwise, click Organize Now to run the rule manually.

For a full walkthrough of setting up folders and rules, see our Getting Started guide. To compare Free and Pro features including Auto Mode, visit our pricing page.

Testing Your Patterns Before Using Them

Regex can be tricky to get right on the first try. Before adding a pattern to File Arbor, we strongly recommend testing it on regex101.com. Here is how:

  1. Open regex101.com in your browser
  2. Make sure the flavor is set to ECMAScript (JavaScript) since that is what File Arbor uses internally
  3. Paste your pattern in the "Regular Expression" field
  4. In the "Test String" area, type several file names -- both ones that should match and ones that should not
  5. The site highlights matches in real time and explains each part of your pattern

This takes thirty seconds and can save you from accidentally moving the wrong files. It is an essential habit for anyone working with regex.

Common Mistakes and How to Fix Them

Even experienced developers trip on these. Here are the most frequent regex pitfalls in file organization and their fixes.

Forgetting to Escape the Dot

The dot . in regex means "any character." When you want to match a literal period (like in a file extension), you must escape it with a backslash.

# Wrong - matches "reportXpdf" as well as "report.pdf"
report.pdf

# Correct - only matches a literal dot
report\.pdf

This is the single most common mistake. Every file extension pattern should use \. before the extension letters.

Patterns That Are Too Greedy

The .* quantifier is greedy by default. It matches as much as possible. This is usually fine for file names since they are short strings, but it can cause unexpected behavior when combined poorly.

# Too broad - matches literally any PDF
.*\.pdf$

# Better - matches invoices specifically
^invoice.*\.pdf$

Be as specific as you can with the beginning of your pattern. Use ^ to anchor to the start of the file name whenever the files you are targeting share a common prefix.

Case Sensitivity

By default, regex is case-sensitive. invoice does not match "Invoice" or "INVOICE." In File Arbor, you can enable the Case Insensitive toggle when creating a Custom Rule. Alternatively, you can handle it in the pattern itself:

# Handles common case variations manually
^(invoice|Invoice|INVOICE).*\.pdf$

# Or use a character class for the first letter
^[iI]nvoice.*\.pdf$

The case-insensitive toggle in File Arbor is cleaner and is the recommended approach.

Forgetting the End Anchor for Extensions

Without $ at the end, your extension pattern might match things you did not intend:

# Wrong - matches "photo.jpg.bak" and "photo.jpg_backup"
.*\.jpg

# Correct - only matches files that END with .jpg
.*\.jpg$

Always use $ when matching file extensions to ensure the extension is at the very end of the file name.

Overly Complex Patterns

If your pattern is getting long and unreadable, consider splitting it into multiple rules. Two simple rules are better than one incomprehensible regex. File Arbor lets you create as many Custom Rules as you need, so there is no reason to cram everything into a single pattern.

# Instead of one monster pattern for all media...
# Rule 1: Images
\.(jpg|jpeg|png|gif|webp|svg)$

# Rule 2: Videos
\.(mp4|avi|mkv|mov|wmv)$

# Rule 3: Audio
\.(mp3|wav|flac|aac|ogg)$

Each rule can send files to a different destination, giving you cleaner organization and easier maintenance.

Building Your Own Patterns

Once you are comfortable with the basics, building custom patterns follows a simple process:

  1. Look at your files. What do the file names you want to match have in common? Write down the common elements.
  2. Identify the variable parts. What changes between files? Dates, numbers, project names? These become regex wildcards or character classes.
  3. Write the pattern. Start simple. Get the basics matching first, then add precision.
  4. Test on regex101.com. Paste real file names from your folders and verify.
  5. Preview in File Arbor. Use the Preview button to double-check against your actual files.
  6. Iterate. If something is off, adjust and test again.

The patterns in this guide cover the most common scenarios, but your files are unique to you. The combination of regex knowledge and File Arbor's Smart Rules gives you the flexibility to handle any organizational challenge.

What's Next?

You now have the foundation to use regex for file organization like a pro. Start with the ready-made patterns above, customize them for your file naming conventions, and let File Arbor handle the rest.

Here are your next steps:

  • Download File Arbor if you have not already
  • Set up your first regex rule using the patterns from this guide
  • Explore all features on our features page including Auto Mode and Quick Rules
  • Check our pricing at the pricing page to unlock unlimited rules and Auto Mode

The days of manually dragging files into folders are over. With regex and File Arbor, your files organize themselves.