Find/Replace Dialog Boxes
(tick_24All Editions)


Regular Expressions

The find and replace dialogs support regular expressions. Be sure to check the Regular expressions option when using regular expressions and to uncheck it when not.

Searching Text with Regular Expressions

Escape Sequences

\xnn - char with hex code nn

\x{nnnn} - char with hex code nnnn (one byte for plain text and two bytes for Unicode)

\t - tab (HT/TAB), same as \x09

\n - newline (NL), same as \x0a

\r - carriage return (CR), same as \x0d

\f - form feed (FF), same as \x0c

\a - alarm (bell) (BEL), same as \x07

\e - escape (ESC), same as \x1b

To match text on more than one line, try using \r\n to match a line break.

Character Classes

You can specify a character class, by enclosing a list of characters in square brackets ([]), which will match any one character in the class. If the first character after the "['' is "^'', then the class matches any character not in the list. Examples:

foob[aeiou]r - finds strings 'foobar', 'foober' etc. but not 'foobbr', 'foobcr' etc.

foob[^aeiou]r - find strings 'foobbr', 'foobcr' etc. but not 'foobar', 'foober' etc.

Within a list of characters, the "-'' character is used to specify a range, so that a-z represents all characters between 'a' and 'z'', inclusive. If you want '-' itself to be a member of a class, then put it at the start or end of the list, or escape it with a backslash. If you want ']' then place it at the start of list or escape it with a backslash. Examples:

[-az] - matches 'a', 'z' and '-'

[az-] - matches 'a', 'z' and '-'

[a\-z] - matches 'a', 'z' and '-'

[a-z] - matches all twenty six lowercase characters from 'a' to 'z'

[\n-\x0D] - matches any of #10,#11,#12,#13.

[\d-t] - matches any digit, '-' or 't'.

[]-a] - matches any char from ']'..'a'.

Metacharacters - Line Separators

^ - start of line

$ - end of line

\A - start of text

\Z - end of text

. - any character in line

The '^' metacharacter by default is only guaranteed to match at the beginning of the input string/text, the '$' metacharacter only at the end. Embedded line separators will not be matched by '^' or '$'. You may, however, wish to treat a string as a multi-line buffer, such that the '^' will match after any line separator within the string, and '$' will match before any line separator. You can do this by switching on the modifier /m. This modifier is on by default.

The \A and \Z are just like '^' and '$', except that they won't match multiple times when the modifier /m is used, while '^' and '$' will match at every internal line separator.

The '.' metacharacter by default matches any character, but if you switch off the modifier /s, then '.' won't match embedded line separators. More information:

'^' is at the beginning of a input string, and, if modifier /m is on (it is by default), also immediately following any occurrence of \x0D\x0A or \x0A or \x0D (and also \x2028 or \x2029 or \x0B or \x0C or \x85). Note that there is no empty line within the sequence \x0D\x0A.

'$' is at the end of a input string, and, if modifier /m is on (it is by default), also immediately preceding any occurrence of \x0D\x0A or \x0A or \x0D (and also \x2028 or \x2029 or \x0B or \x0C or \x85). Note that there is no empty line within the sequence \x0D\x0A.

'.' matches any character, but if modifier /s is off then '.' doesn't match \x0D\x0A and \x0A and \x0D (and also \x2028 and \x2029 and \x0B and \x0C and \x85).

Note that '^.*$' (an empty line pattern) does not match the empty string within the sequence \x0D\x0A, but matches the empty string within the sequence \x0A\x0D.

Metacharacters - Predefined Classes

\w - an alphanumeric character (including "_")

\W - a nonalphanumeric

\d - a numeric character

\D - a non-numeric

\s - any space (same as [ \t\n\r\f])

\S - a non space

Metacharacters - Word Boundaries

A word boundary (\b) is a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \W.

\b - Match a word boundary

\B - Match a non-(word boundary)

Metacharacters - Iterators

Any item of a regular expression may be followed by another type of metacharacters - iterators. Using these metacharacters you can specify the number of occurrences of a previous character, metacharacter or subexpression.

* - zero or more ("greedy"), similar to {0,}

+ - one or more ("greedy"), similar to {1,}

? - zero or one ("greedy"), similar to {0,1}

{n} - exactly n times ("greedy")

{n,} - at least n times ("greedy")

{n,m} - at least n but not more than m times ("greedy")

*? - zero or more ("non-greedy"), similar to {0,}?

+? - one or more ("non-greedy"), similar to {1,}?

?? - zero or one ("non-greedy"), similar to {0,1}?

{n}? - exactly n times ("non-greedy")

{n,}? - at least n times ("non-greedy")

{n,m}? - at least n but not more than m times ("non-greedy")

Digits in curly brackets of the form {n,m}, specify the minimum number of times to match the item (n) and the maximum (m). The form {n} is equivalent to {n,n} and matches exactly n times. The form {n,} matches n or more times. There is no limit to the size of n or m, but large numbers will use more memory and slow down execution. If a curly bracket occurs in any other context, then it is treated as a regular character. Examples:

foob.*r - matches strings like 'foobar', 'foobalkjdflkj9r' and 'foobr'

foob.+r - matches strings like 'foobar', 'foobalkjdflkj9r' but not 'foobr'

foob.?r - matches strings like 'foobar', 'foobbr' and 'foobr' but not 'foobalkj9r'

fooba{2}r - matches the string 'foobaar'

fooba{2,}r - matches strings like 'foobaar', 'foobaaar', 'foobaaaar' etc.

fooba{2,3}r - matches strings like 'foobaar', or 'foobaaar' but not 'foobaaaar'

Metacharacters - Alternatives

Use '|' to separate a series of alternatives in a pattern so that fee|fie|foe will match any of "fee'', "fie'', or "foe'' in the target string (as would f(e|i|o)e). The first alternative includes everything from the last pattern delimiter ('(', '[', or the beginning of the pattern) up to the first '|', and the last alternative contains everything from the last '|' to the next pattern delimiter. For this reason, it's common practice to include alternatives in parentheses, to minimize confusion about where they start and end.

Alternatives are tried from left to right, so the first alternative found for which the entire expression matches, is the one that is chosen. This means that alternatives are not necessarily greedy. For example: when matching foo|foot against "barefoot'', only the "foo'' part will match, as that is the first alternative tried, and it successfully matches the target string. (This might not seem important, but it is important when you are capturing matched text using parentheses.)

Also remember that '|' is interpreted as a literal within square brackets, so [fee|fie|foe] only matches [feio|].

About Greediness

A little explanation about "greediness". "Greedy" takes as many as possible, "non-greedy" takes as few as possible. For example, 'b+' and 'b*' applied to string 'abbbbc' returns 'bbbb', 'b+?' returns 'b', 'b*?' returns an empty string, 'b{2,3}?' returns 'bb', 'b{2,3}' returns 'bbb'. You can switch all iterators into "non-greedy" mode (see the modifier /g).

Replacing Text

Subexpressions and Substitution

You can match subexpression with the find text and insert the subexpression in the replace text.

Use parenthesis ( ... ) in the find text to specify the subexpressions.

In the replace text:

Use $0 or $& to specify the entire expression.

Use $1 to specify the first subexpression in the find text.

Use $N to specify the Nth subexpression in the find text. N's range is 1 to 16.

If you want to actually use a '$' or '\' character, then use \$ or \\ (prefix with '\').


Modifiers change the behavior of regular expressions. There are many ways to set up modifiers. Any of these modifiers may be embedded within the regular expression itself using the (?imsxr-imsxr) construct.

i - Do case-insensitive pattern matching (using installed in the system locale settings).

m - Treat the document as multiple lines. That is, change '^' and '$' from matching at only the very start or end of the string to the start or end of any line anywhere within the string. This modifier is on by default.

s - Treat the document as a single line. That is, change '.' to match any character whatsoever, even a line separator, which it normally would not match.

g - Non standard modifier. Switch off to switch all the following operators into non-greedy mode (by default this modifier is on). So, if modifier /g is off then '+' works as '+?', '*' as '*?' and so on.

x - Extend the pattern's legibility by permitting whitespace and comments (see explanation below).

The modifier /x itself needs a little more explanation. It ignores whitespace that is neither backslashed nor within a character class. You can use this to break up regular expression into (slightly) more readable parts. The '#' character is also treated as a metacharacter introducing a comment, for example:

   (abc) # comment 1
    |   # You can use spaces to format - they are ignored
   (efg) # comment 2 

This also means that if you want real whitespace or the '#' characters in the pattern (outside a character class, where they are unaffected by /x), then you'll either have to escape them or encode them using octal or hex escapes. Taken together, these features go a long way towards making regular expressions text more readable.