Regular Expressions Quick Reference
Several areas of DeltaWalker Classic—the text and folder comparison filters as well as the Find/Replace dialog—use regular expressions to search for and match text. With regular expressions, you can describe a wide range of patterns and be very precise about the text to match.
DeltaWalker Classic uses the regular expressions of the Java 21 runtime it ships with. This section gives a brief introduction to their syntax. For the complete reference, see the links in the See Also section below.
Literals
All characters except the ones below match themselves. The characters below match themselves only when escaped with a backslash (\) placed right before them:
\ . [ ] ^ $ ? * + { } | ( )
For example, \. matches a period and \\ matches a backslash.
Literal escapes
The following table lists special uses of the backslash (\) for matching certain characters:
| Construct | Matches |
|---|---|
\t | The tab character |
\n | The newline (line feed) character |
\r | The carriage-return character |
\f | The form-feed character |
\a | The bell (alert) character |
\e | The escape character |
\0n | The character with octal value 0n (0 <= n <= 7) |
\0nn | The character with octal value 0nn (0 <= n <= 7) |
\0mnn | The character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7) |
\xhh | The character with hexadecimal value 0xhh |
\uhhhh | The character with hexadecimal value 0xhhhh |
\x{h...h} | The character with hexadecimal value 0xh…h |
\cx | The control character corresponding to x |
Character classes
The dot (.) matches any character except a line terminator. It is the simplest and most widely used of the character classes—sub-expressions that match one character out of a set:
| Construct | Matches |
|---|---|
[abc] | a, b, or c (simple class) |
[^abc] | Any character except a, b, or c (negation) |
[a-zA-Z] | a through z or A through Z, inclusive (range) |
[a-d[m-p]] | a through d, or m through p: [a-dm-p] (union) |
[a-z&&[def]] | d, e, or f (intersection) |
[a-z&&[^bc]] | a through z, except for b and c: [ad-z] (subtraction) |
[a-z&&[^m-p]] | a through z, and not m through p: [a-lq-z] (subtraction) |
\d | A digit: [0-9] |
\D | A non-digit: [^0-9] |
\s | A whitespace character: [ \t\n\x0B\f\r] |
\S | A non-whitespace character: [^\s] |
\w | A word character: [a-zA-Z_0-9] |
\W | A non-word character: [^\w] |
\h | A horizontal whitespace character, such as a space or a tab |
\R | Any line break: \r\n, \n, \r, and other Unicode line breaks |
Boundary matchers
Outside a character class, the ^ character does not match a character but the beginning of a line. Other expressions that match boundaries are:
| Construct | Matches |
|---|---|
^ | The beginning of a line |
$ | The end of a line |
\b | A word boundary |
\B | A non-word boundary |
\A | The beginning of the input |
\G | The end of the previous match |
\Z | The end of the input but for the final terminator, if any |
\z | The end of the input |
Quantifiers
Quantifiers specify how many times the expression before them must match. The following table lists the most common forms:
| Construct | Matches |
|---|---|
X? | X, once or not at all |
X* | X, zero or more times |
X+ | X, one or more times |
X{n} | X, exactly n times |
X{n,} | X, at least n times |
X{n,m} | X, at least n but not more than m times |
Quantifiers are greedy: they match as much text as they can. Add ? after a quantifier, as in X*? or X+?, to match as little text as possible instead.
Logical alternation
When a match is possible according to different expressions, the | character separates the alternatives. For example, X|Y matches either X or Y.
Groups
Parentheses group the elements of a regular expression into sub-expressions, so that quantifiers and alternation can apply to them. For example, (ab)+ matches ab, abab, and so on. A group also captures the text it matches: \1 matches the text captured by the first group again. To group without capturing, write (?:X).
Flags
Place (?i) at the start of an expression to make it ignore character case.
See Also
- Pattern (Java SE 21 API) , the complete syntax reference
- “Regular expression”, Wikipedia
- All Comparisons > Text Filters
- Folder Comparisons > Filters
- Find/Replace Dialog