Regular expressions
You can perform sophisticated find and replace operations in Microsoft FrontPage by using regular expressions. A regular expression is a pattern of ordinary and special characters that describe one or more strings to find when searching text or code. Regular expressions are useful when you do not know the exact text or code you are looking for, or when you are looking for all occurrences of strings of text or code with one or more similarities.
To use regular expressions, open the Find and Replace dialog box in FrontPage, select the Regular expressions check box search option, and type a regular expression pattern in the Find what box. You can access some of the more common syntax characters using the Regular expressions arrow.
When you use regular expressions in your searches, there are specific rules that control which combination of characters perform specific matches. Each regular expression, or combination of regular expressions is referred to as syntax. You can use multiple regular expressions in one syntax to precisely target your search.
The regular expressions in FrontPage and the associated syntax are described in the table that follows.
Expression | Syntax | Description |
Any character | . | Acts as a wild card to match any single printing or non-printing character with the exception of the newline (\n)character. For example, the regular expression |
Maximal |
* | Matches zero or more occurrences of a character that precede the expression, matching as many characters as possible. The regular expression For example, the regular expression |
Maximal |
+ | Matches one or more occurrences of a character that precede the expression, matching as many characters as possible. The regular expression For example, the regular expression |
Minimal |
@ | Matches zero or more occurrences of a character that precede the expression, matching as few characters as possible. The regular expression For example, the regular expression |
Minimal |
# | Matches one or more occurrences of a character that precede the expression, matching as few characters as possible. For example, the regular expression |
Set of characters | [ ] | Matches any one of the characters within the brackets ([ ]). You can specify ranges of characters by using a hyphen (-), as in [a-z] .Examples:
|
Beginning of line | ^ | Anchors the match to the beginning of a line. For example, the regular expression |
End of line | $ | Anchors the match to the end of a line. For example, the regular expression |
Beginning of file | ^^ | Anchors the match to the beginning of a file. Works only when searching for text in source code or in text files. For example, to match the first HTML tag at the beginning of a file, use the following regular expression: |
End of file | $$ | Anchors the match to the end of a file. Works only when searching for text in source code or in text files. For example, to match the last HTML tag at the end of a file (with no spaces following the tag), use the following regular expression: |
Or | | | Indicates a choice between two items, thereby matching the expression before or after the OR symbol (|). For example, the regular expression
but it does not match the line "it belongs to them." |
Escape special character | \ | Matches the character following the back slash ( \ ). This allows you to find characters that are used in the regular expression syntax, such as a left curly brace ({) or a caret (^) or some other special character. For example, you can use |
Tagged expression | {} | Tags the text matched by the enclosed expression. You can match another occurrence of the tagged text in a Find expression or insert the tagged text in a Replace expression using \N. For example, suppose you are looking to find two duplicate, consecutive words. To search, use the following expression: With the assumption that the consecutive words are separated by a single space, you'll want to add a space between the right curly brace (}) and the back slash ( \ ). In this example, we combine the sharp sign (#) and the period (.) with the curly braces ({}) to make one syntax. In this expression, |
Nth tagged expression | \N | In a Find expression, \N matches the text matched by the Nth tagged expression, where N is a number from 1 to 9. In a Replace expression, \N inserts the text matched by the Nth tagged expression where N is a number from 1 to 9. \0 inserts the text matched by the entire Find expression. For example, suppose you want to find two duplicate, consecutive words and replace them with a single word. To search, use the following expression: With the assumption that the consecutive words are separated by a single space, you'll want to add a space between the right curly brace (}) and the back slash ( \ ). In this example, we combined the sharp sign (#) and the period (.) with the curly braces ({}) to make one syntax. To replace, use the following expression: \1 represents what was found in the first pair of curly braces in the find string. By using \1 in the replace action, you essentially replace the duplicate, consecutive words with a single copy of the word. |
Group expression | ( ) | Marks the beginning and end of a subexpression. A subexpression is a regular expression that you enclose in parenthesis ( ), such as the expression that follows: This expression matches the following occurrences 'haha' and 'hahaha'. |
Prevent match | ~x | Prevents a match when x appears at this point in the expression. For example, the regular expression |
Line break | \n | Matches a new line in Code view, or a <br> in Design view. The syntax (\n), is a shorthand approach to enable you to match all line breaks. |
Tab | \t | Matches a single tab character. For example, if you want to find all single tabbed characters at the beginning of a line, the regular expression would look like the following:
In this example, we combine the caret (^) and the plus sign (+) with the tab (\t) to make one syntax. The caret (^) that precedes the single tab character expression, anchors the match to all tabbed characters at the beginning of the line. The plus sign (+) represents the matching of one or more tab characters. |
Any one character not in the set | [^] | Matches any character that is not in the set of characters that follows the caret (^). For example, to match any character except those in the range, use the caret (^) as the first character after the opening bracket. The expression |
Repeat expression | ^n | Matches n occurrences of the expression that precedes the caret (^). For example, with n equaling 4, the expression |
Alphanumeric character | :a | Matches the expression [a-zA-Z0-9] . You can use the following expression: |
White space | :b | Matches any white spaces in code or text. For example, to match a single white space character at the beginning of a line, use the following regular expression: |
Alphabetic character | :c | Matches the expression [a-zA-Z] When you use this expression, it enables you to match all upper or lower case letters. You can use the shorthand expression |
Decimal digit | :d | Matches the expression[0-9] This expression enables you to match any digit. For example, suppose you want to find a social security number in a text file. The format for U.S. social security numbers is 999-99-9999. You can use the shorthand expression |
Hexadecimal digit | :h | Matches the expression [0-9a-fA-F]+ Use a this expression when you want to match a hexadecimal combination of any upper or lower case letters between 'A' and 'F', and any numbers. For example, suppose the pages in your Web site have multiple different background colors and you want to change the color of those pages to black, such as 000000. However, you do not know what the hexadecimal numbers are for the existing colors. Use the following regular expression to find all existing hexadecimal numbers: \#:h You could use [0-9a-fA-F] to search, but in this example we combine the back slash (\) and the sharp sign (#) with the hexadecimal digit (:h) syntax. \# matches a non-expression sharp sign (#) and :h matches any sequence of hexadecimal characters. To replace the existing hexadecimal numbers, type the hexadecimal number of the background color that you want:
|
Identifier | :i | Matches the expression [a-zA-Z_$][a-zA-Z0-9_$]* When working with code, if you want to match all program identifiers, you can use the shorthand expression |
Rational number | :n | Matches the expression ([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)|([0-9]+) If you want to match all whole numbers that contain a decimal point, you can use the shorthand expression |
Quoted string | :q | Matches the expression ("[~"]*")|('[~']*') If you want to match all quotes surrounded by quotation marks, you can use the shorthand expression |
Alphabetic string | :w | Matches the expression [a-zA-Z]+ This syntax is a shorthand approach to enable you to match one or more alphabetical characters, either lower case or upper case. |
Decimal integer | :z | Matches the expression [0-9]+ This syntax is a shorthand approach to enable you match any number from zero or more. |