Magic File Renamer Help


Regular Expressions

Regular expressions are used in the Replacer and Replace List filters to match a pattern of text instead of a fixed literal. Patterns use .NET regular-expression syntax. An invalid pattern is reported when the filter is set up.

Match case is off by default, so jpg also matches JPG. Whole word matches only when the pattern is a whole word. * and + match as much as they can.

Common pattern elements

Element Meaning Example
. Any one character a.c matches abc and a-c
\d / \D A digit / not a digit \d+ matches 14
\w / \W Letter, digit, or underscore / anything else \w+ matches Track_2
\s / \S Whitespace / not whitespace \s+ matches one or more spaces
[abc] / [^abc] One character in the set / not in the set. A hyphen is a range ([0-9], [a-z]) [._-] matches ., _, or -
\ Escape the next character so it is literal (. * + ? ( ) [ ] { } ^ $ | \) \. matches a dot; \( matches (
| Either pattern jpe|jpeg matches jpe or jpeg
* / + / ? The previous item, zero or more / one or more / optional [0-9]+ matches 02; s? makes the s optional
{n} / {n,} / {n,m} The previous item, exactly n / at least n / from n to m \d{4} matches a four-digit year
^ / $ Start / end of the text ^[0-9]+ matches digits only at the start
\b Word boundary (between a word character and a non-word character) \bfeat\b matches feat but not feature
(…) Capture group. Groups are numbered left to right by the opening parenthesis \((.*)\) captures the text inside parentheses as group 1

Replacement

Text that matched the pattern can be reused in Replace with. The replacement may also include formatter tokens such as <file-name>.

Token Inserts
$0 The whole match
$1…$9 Captured group 1 through 9
$$ A literal $

Examples

Search Replace Source Result
[0-9]+_-_ (blank) 14_-_Tears_For_Fears_-_Pharaohs Tears_For_Fears_-_Pharaohs
\(.*\) BOOM ab(c)d abBOOMd
\((.*)\) $1 ab(c)d abcd
jpeg|jpe jpg house.jpe house.jpg
^[0-9]+ _ 02Track2 _Track2