Appendix A. Regular Expressions


Regular expressions describe patterns that you can use to search code and text. Searching with regular expressions is covered in Lesson 17. The following table lists the special characters that are used in regular expressions, descriptions of their meanings, and examples of their matches.

Type

Description

Example

^

Beginning of input or line

^T matches "T" in "This good earth," but not in "Uncle Tom"

$

End of input or line

h$ matches "h" in "teach," but not in "teacher"

*

The preceding character zero or more times

um* matches "um" in "rum," "umm" in "yummy," and "u" in "huge"

+

The preceding character one or more times

um+ matches "um" in "rum" and "umm" in "yummy," but nothing in "huge"

?

The preceding character zero or one time

st?on matches "son" in "Johnson" and "ston" in "Johnston" but nothing in "Appleton" or "tension"

.

Any single character except newline

.an matches "ran,""can," and "and" in the phrase "bran muffins can be tasty and healthy"

x|y

Either x or y

FF0000|000FF matches "FF0000" in bgcolor="#FF0000" and "0000FF" in font color="#0000FF"

{n}

Exactly n occurrences of the first the preceding character

o{2} matches "oo" in "loom" and the first two o's in "mooooo," but nothing in "money"

{n,m}

At least n and at most m occurrences of the preceding character

F{2,4} matches "FF" in "#FF0000" and the first four Fs in "#FFFFFF"

[abc]

Any one of the characters enclosed in the brackets. Specify a range of characters with a hyphen (for example, [a-f]is equivalent to [abcdef].

[e-g] matches "e" in "bed," "f" in "folly," and "g" in "guard"

[^abc]

Any character not enclosed in the brackets. Specify a range of characters with a hyphen (for example, [a-f]is equivalent to [abcdef].

[^aeiou] initially matches "r" in "orange," "b" [^aeiou] initially matches "r" in "orange," "b"

\b

A word boundary (such as a space or carriage return).

\bb matches "b" in "the book," but nothing in "goober" or "snob"

\B

Anything other than a word boundary.

\Bb matches "b" in "goober," but nothing in "the book"

\d

Any digit character. Equivalent to [0-9].

\d matches "3" in "C3PO" and "2" in "apartment 2G"

\D

Any nondigit character. Equivalent to [^0-9].

\D matches "S" in "900S" and "Q" in "Q45"

\f

Form feed

 

\n

Line feed

 

\r

Carriage return

 

\s

Any single white-space Any single white-space, tab, form feed, or line feed.

\sbook matches "book" in "blue book," but nothing in "notebook"

\t

A tab.

 

\w

Any alphanumeric character, including underscore. Equivalent to [A-Za-z0-9_].

b\w* matches "barking" in "the barking dog" and both "big" and "black" in "the big blackdog"

\W

Any non-alphanumeric character. Equivalent to [^A-Za-z0-9_].

\W matches "&" in "Jake & Mattie" and "%" in "100%"





Macromedia Dreamweaver 8(c) Training from the Source
Macromedia Dreamweaver 8: Training from the Source
ISBN: 0321336267
EAN: 2147483647
Year: 2006
Pages: 326

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net