Pattern matching in searches

This functionality lets you perform powerful search and replace actions.

If the Use Pattern Matching option is enabled, the characters in the Find box are interpreted as patterns. That is, the search text can contain special search characters that match a class of text strings, or markup constructs. (If your search text does not contain any special characters, the text is searched for exactly as entered.) The following special characters can be used:

. * ? + ^ $ [ ]

In addition, the character < is used to indicate an element search when it appears as the first character in the pattern. To search for any special character as ordinary text when Use Pattern Matching is turned on, precede it with a backslash (\). For example:

\.

matches a period. Search patterns can be grouped by enclosing them in parentheses.

Matching any single character

To match any single character, including a blank space, use a period (.). For example:

fo.d

would match "food", "ford", "fond", "fold", etc.

Matching zero or one of something

To match zero or one occurrences of a character, or series of characters enclosed in parentheses, follow the character with a question mark (?). For example:

colou?r

would match both "color" and "colour".

Matching zero or more

To match zero or more occurrences of a character, or series of characters enclosed in parentheses, follow the character with an asterisk (*). For example:

l*ama

would match "ama", "lama", "llama", "lllama", etc.

b(an)*a

would match "ba", "bana", "banana", etc.

You can combine the asterisk and period to match any text starting and ending with specified characters. For example:

s.*ch

would match "search", "such", "stretch", "stopwatch", as well as "sch" and "skip lunch".

Matching one or more of something

To match one or more occurrences of a single character, or text enclosed in parentheses, follow the character with a plus sign (+). For example, the search text:

be+n

would match "ben", "been", etc., but would not match "bn".

Matching either of two

To search for either of two search patterns, separate them with a pipe or vertical bar (|). For example, to search for "love" or "money" use:

love|money

You can combine this with other search patterns. For example, to find "truth" or "dare":

tr.th|d.*e

Matching just after markup

To search for text only when it immediately follows a start or end-tag, start the search pattern with a caret (^). For example, to find the word "Note" at the start of a paragraph use:

^Note

Matching just before markup

To search for text only when it is immediately followed by a start or end tag, end the search pattern with a dollar sign ($). The dollar sign is not treated as a special search character unless it is at the end of a search pattern. There cannot be white space between the text to be found and the tag. For example, to search for the word "sub" immediately preceding a tag, use:

sub$

Matching character ranges

To define a range of characters to be matched, surround the group of characters with square brackets ([ and ]). The simplest form of character range matches any one of the characters within the brackets. For example:

t[ai]n

matches "tan" and "tin".

A range of characters matches any character in that range of the alphabet. For example:

[b-d]

matches "b", "c", or "d". The pattern:

[A-Za-z0-9]

matches any alphanumeric character. If Match Case is turned off, the character range [a-z] matches any upper- or lower-case letter

To reverse the meaning of a character range—that is, to match characters not in the range—place a caret (^) before the range. For example:

th[^ei]n

matches "than", but not "then" or "thin". The expression:

[^m-p]

would match any lower-case letter in the alphabet before "m" or after "p".

Re-using search text

To use a sub-expression in the search text in the replace text, surround the sub-expression with parentheses: ( and ). Then refer to the sub-expression in the replace text in the form \n , where n is a number from 1 to 9. This is replaced with whatever the nth expression in brackets in the search text has matched. For example, if the search text is:

(.)read

and the replace text is:

\1ox

then if the text "bread" is found, it is replaced with "box". The expression \1 is replaced by the matched text for the first expression in parentheses in the search text: in this case (.) was matched by b.

Here is an example with more than one sub-expression. This time, let us say the search text is:

(v.*e) (v.*a)

and the replace text is:

\2 \1

Now, what happens if the text "vice versa" is found? The first sub-expression, "(v.*e)", matches "vice"; and the second sub-expression, "(v.*a)", matches versa. In the replace text, the second expression found is followed by the first, so the text becomes "versa vice".

You can even nest sub-expressions. The sub-expressions are numbered according to the order of their left parentheses. For example, if the search text is:

(cad(abra))

and the replace text:

\2\1

"cadabra" is replaced by "abracadabra".

To retain the entire matched text, use \0 in the replace text. For example, if the search text is:

fish

and the replace text is:

gone \0ing

then "fish" is replaced with "gone fishing".

You can use \n expressions in attribute replacement values: one application of this is to change a group of URLs. For example, if you want to change all of the filenames in your A elements to have the ".htm" file extension instead of ".html", use the following find text:

<a href="(.*)html"

and the replace text:

<a href="\1htm"

The element is matched by "<a"; the attribute that contains the URL value is called href; the pattern "(.*)" matches everything in the URL up to the extension; that matched text is substituted for "\1" in the replacement text; and the new extension is added.