Regular Expression Rule
File names with dates and numbers mixed together? Want to precisely extract specific parts? Regular expressions help you handle complex pattern matching and replacement.
This Feature Helps You
- Organize dated files: Formats like
IMG_20231201_001.jpgthat you want to change to standardized2023-12-01_No001.jpg - Batch remove bracketed content: Files like
文件(副本).txt,照片(2).jpg- want to remove all brackets and their contents - Extract and reorganize fields: Multiple pieces of information mixed in file names that you want to rearrange in your own order
- Precise matching and replacement: Complex rules that simple find-and-replace can't handle, like "only change number parts", "only change dates in specific format"
Quick Start (3 Steps)
- Click "Add Rule" button → Select "Regex"
- Fill two fields:
- Regex Pattern: For example
IMG_(\d{8})_(\d{3})(matches IMG_ prefix + 8 digits + _ + 3 digits) - Replace With: For example
Photo_$1_No$2($1 and $2 represent matched content)
- Regex Pattern: For example
- Preview first, then apply when confirmed, avoiding batch incorrect changes
Examples
Example 1: Unify Various Number Formats
❌ Original Files: 文档No.001.pdf, 报告#002.pdf, 图片[003].pdf, 视频_004.pdf...
😫 Problem: Files collected from different sources have various number formats (some No., some #, some [], some _), want to extract just the numbers and change to 文件001.pdf format
✅ Operation:
- Regex Pattern:
(.*?)(?:No\.|#|\[|_)(\d+)(?:\])? - Replace With:
$1$2
✅ Result: 文档001.pdf, 报告002.pdf, 图片003.pdf, 视频004.pdf
Why this setup:
(.*?)non-greedy matches file name beginning,(?:No\.|#|\[|_)matches various number prefixes (without capturing),(\d+)captures number part,(?:\])?optionally matches right bracket. Finally$1$2keeps only file name and number, removing all number symbols.
Example 2: Clean Special Symbols from File Names
❌ Original Files: 项目文档@最终版!.docx, 照片~2023#.jpg, 报告$重要%.pdf...
😫 Problem: Downloaded or copied file names mixed with various special symbols (@!~#$%), want to keep only Chinese, English, numbers and common separators
✅ Operation:
- Regex Pattern:
[^a-zA-Z0-9\u4e00-\u9fa5_\-\s] - Replace With: (leave empty)
- Global: Enabled
✅ Result: 项目文档最终版.docx, 照片2023.jpg, 报告重要.pdf
Why this setup:
[^...]means "characters not in this range",a-zA-Z0-9is English and numbers,\u4e00-\u9fa5is Chinese,_\-\sis underscore, hyphen and space. Leaving replace empty removes all special symbols not in this range. Enabling "Global" removes special symbols at all positions.
Example 3: Extract Key Information from Mixed Formats
❌ Original Files: 【重要】项目报告-2023.pdf, [紧急]会议记录_1201.docx, (待办)任务清单 v2.xlsx...
😫 Problem: Tags at the beginning of file names in inconsistent formats (【】, [], ()), want to remove all tags and keep only the content after
✅ Operation:
- Regex Pattern:
^[\[【(].*?[\]】)]\s* - Replace With: (leave empty)
✅ Result: 项目报告-2023.pdf, 会议记录_1201.docx, 任务清单 v2.xlsx
Why this setup:
^means file name beginning,[\[【(]matches any left bracket type,.*?non-greedy matches bracket contents,[\]】)]matches corresponding right bracket,\s*matches possible spaces after bracket. Leaving replace empty removes the entire tag part.
Fields to Fill
Basic Settings
-
Regex Pattern The pattern you want to match, like
IMG_(\d{8})_(\d{3}),\([^)]*\)(Cannot be empty, otherwise nothing will change)Beginner Tips:
\dmeans digit,\d{8}means 8 digits()parentheses mean "capture group", can reference with$1,$2.*means any content,.*?is non-greedy mode (matches as little as possible)- Special characters need
\escape, like\(,\),\.
-
Replace With What to change to, like
$1-$2-$3,Photo_$1(Leave empty = delete matched content) (Can use$1,$2... to reference capture groups in regex)
Advanced Options (Can ignore, defaults work fine)
-
Global Default enabled, replaces all matches in file name. If you only want to replace first match, disable this option.
-
Case Sensitive Default unchecked,
IMGandimgtreated the same. When checked,IMGandimgtreated as different words. -
Ignore Extension Default checked, only processes file name, doesn't touch
.jpg,.txtsuffixes. If you really need to match extensions with regex, uncheck this option.
FAQ
❓ I don't know how to write regex?
Suggestion 1 (beginner-friendly): Try simple patterns first, like:
\d+: Matches all numbers[a-zA-Z]+: Matches all letters_,-: Write plain characters directly
Suggestion 2 (quick learning): Online tool regex101.com lets you test your regex in real-time with detailed explanations.
Suggestion 3 (simple scenarios): If you just want to replace fixed words, use Find & Replace rule - it's simpler.
❓ Replace result is wrong?
-
Check parenthesis positions
$1,$2correspond to()parentheses in your regex, counting from left to right -
Try non-greedy mode If
.*matched too much, change to.*? -
Test in preview Test with a few files first, see if match results are what you want
❓ "Invalid regular expression" error?
Most common causes:
- Unmatched parentheses (wrote
(but not)) - Special characters not escaped (to match
.need to write\.) - Wrong backslash usage (Windows path
\should be\\)
❓ What's the difference between global and non-global matching?
Global enabled (default): file(1)(2).txt → Removes all brackets → file.txt
Global disabled: file(1)(2).txt → Only removes first bracket → file(2).txt
Important Notes:
- ⚠️ Too broad regex may delete unintended content: For example
.*might match entire file name, test in preview first - ⚠️ Parentheses and escaping easily confused:
()is capture group,\(\)actually matches real parentheses - ⚠️ Be careful with greedy mode:
.*matches as much as possible, use.*?when needing to limit scope
Advanced Techniques
- ✅ Combine with "Sequence Number": First use regex to remove old numbers, then use sequence number to add new unified-length numbers
- ✅ Combine with "Date & Time": First use regex to extract dates from file names, then use date & time rule to change format
- ✅ Need simple replacement?: If just changing fixed words, Find & Replace is simpler
- ✅ Regex too complex?: Can split into two steps - first use regex to clean, then use other rules to supplement
What to Read Next?
- Find & Replace: Faster for simple scenarios, no regex needed
- Remove Text: Delete content by position, more intuitive than regex
- Date & Time: Dedicated rule for date format conversion