Actions in Depth
Basic Regular Expression Syntax
A one-page regular expression reference for Better Rename: anchors, wildcards, character classes, quantifiers, capture groups and examples.
A regular expression defines a text (i.e. character string) pattern and assigns a variable to each component of the pattern.
The basic rules for patterns are:
^Beginning of string$End of string.Any character\dAny digit,\wany letter, digit or underscore,\sa space or tab[Start of character list]End of character list(Start of expression group)End of expression group|ORs two expressions\Escape character:\.\(\[\+match a literal dot, bracket, plus sign*Preceding expression occurs zero or more times?Preceding expression occurs zero or one times+Preceding expression occurs one or more times{4}Preceding expression occurs exactly 4 times,{2,3}two or three times- All other characters match themselves
The [ and ] characters can enclose character lists:
[ab]denotes a single lowercase a or b letter[a-z]any lowercase letter[0-9]any digit[0-9]+any number[a-zA-Z0-9]any letter or digit[ _-]a space, an underscore or a hyphen
Examples:
.*denotes any sequence of characters.* .*denotes any string of characters that includes a space-
.*matches as much as it can (“greedy”);.*?matches as little as it can. InMovie (2019) (Cut), the pattern\(.*\)matches from the first(to the last), whereas\(.*?\)matches(2019)only. -
You use “capture groups” to determine which parts of the text will be grouped together and put into a variable. You achieve this grouping by placing brackets around the capture group:
-
(.*) (.*)creates two capture groups$1and$2;$1will contain all characters before the space and$2will contain all characters after the space - As mentioned before the different capture groups will be placed into capture variables. These variables are denoted by
$1,$2,$3,$4, etc.$0is a special variable that holds the entire matched pattern.
The older \1, \2, \3, etc. capture variable syntax is accepted as well in both regular expression actions,
so patterns written for other tools can be pasted in unchanged. We recommend the now standard $1, $2, $3, etc.
syntax for new patterns.
The full syntax supported by the modern engine is documented on the ICU website.