HTML and CSS Reference
In-Depth Information
Appendix A. Regular Expressions
Regular expressions enable one to search for common patterns in text files. Many tools support regular-
expression-based search and replace. Although there are small differences in syntax from one tool to the next,
most of the syntax and the basic ideas are much the same.
Characters That Match Themselves
The first rule of regular expressions is that most normal characters match themselves. A "normal" character is a
letter, a digit, or a space. Thus, the regular expression "Al Gore was elected president in the year 2000"
matches exactly the string "Al Gore was elected president in the year 2000" and no others. Searching for that
string will find all occurrences of that exact string in the searched document or documents. However, it will not
find even slight variations, such an extra space between the words Al and Gore . Table A.1 shows some more
examples.
Table A.1. Characters That Match Themselves
Pattern
Matches
Example
Foo
The string Foo
Foo
foo
The string foo
Foo
foo bar
The string foo bar
foo bar
2000
The string 2000
2000
a e
The string a e
a e
<!DOCTYPE
The string <!DOCTYPE
<!DOCTYPE
<p>
The string <p>
<p>
</p>
The string </p>
</p>
To be specific, the following characters match themselves:
All ASCII letters A-Z and a-z
The ASCII digits 0-9
The space character
All non-ASCII characters: é, ç,... and so on
The following ASCII punctuation characters:
!
 
Search WWH ::




Custom Search