Skip to Content
Everything ElseRegular Expressions Quick Reference

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:

ConstructMatches
\tThe tab character
\nThe newline (line feed) character
\rThe carriage-return character
\fThe form-feed character
\aThe bell (alert) character
\eThe escape character
\0nThe character with octal value 0n (0 <= n <= 7)
\0nnThe character with octal value 0nn (0 <= n <= 7)
\0mnnThe character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7)
\xhhThe character with hexadecimal value 0xhh
\uhhhhThe character with hexadecimal value 0xhhhh
\x{h...h}The character with hexadecimal value 0xh…h
\cxThe 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:

ConstructMatches
[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)
\dA digit: [0-9]
\DA non-digit: [^0-9]
\sA whitespace character: [ \t\n\x0B\f\r]
\SA non-whitespace character: [^\s]
\wA word character: [a-zA-Z_0-9]
\WA non-word character: [^\w]
\hA horizontal whitespace character, such as a space or a tab
\RAny 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:

ConstructMatches
^The beginning of a line
$The end of a line
\bA word boundary
\BA non-word boundary
\AThe beginning of the input
\GThe end of the previous match
\ZThe end of the input but for the final terminator, if any
\zThe end of the input

Quantifiers

Quantifiers specify how many times the expression before them must match. The following table lists the most common forms:

ConstructMatches
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

Last updated on