Character | match | example |
^ | start of input or line. | ^T matches the "T" in "This good earth" but not in "Uncle Tom's Cabin". |
$ | Input or end of line. | h$ matches the "h" in "teach", but not the "h" in "teacher" |
* | 0 or more leading characters. | um* matches "um" in "rum", "umm" in "yummy", and "u" in "huge" |
+ | 1 or more preceding characters. | um+ matches the "um" in "rum" and the "umm" in "yummy", but there is no match in "huge" |
? | The preceding character may appear at most once (i.e., indicating that the preceding character is optional). | st?on matches "son" in "Johnson" and "ston" in "Johnston", but there is no match in "Appleton" and "tension" |
. | Any single character except a newline. | .an matches "ran" and "can" in the phrase "bran muffins can be tasty" |
x|y | x or y. | FF0000|0000FF matches "FF0000" in bgcolor="#FF0000" and "0000FF" in font color="#0000FF" |
{n} | exactly n leading characters. | o{2} matches "oo" in "loom" and the first two "o"s in "mooooo", but there is no match in "money" |
{n,m} | at least n and at most m prefixes character. |
F{2,4} matches any of the characters enclosed in | parentheses |
between the "FF" in "#FF0000" and the first four "F" characters in "#FFFFFF" |
[abc]. Use hyphens to specify a range of characters (for example, [af] is equivalent to [abcdef]).
| [eg] Matches the "e" in "bed", the "f" in "folly", and the "g" in "guard" |
[^abc] | Any characters not enclosed in parentheses. Use hyphens to specify a range of characters (for example, [^af] is equivalent to [^abcdef]). | [^aeiou] initially matches the "r" in "orange", the "b" in "book", and the "k" in "eek!" |
b | word boundaries (such as spaces or carriage returns). | bb matches the "b" in "book", but there is no match in "goober" and "snob" anything |
outside the word boundary | . | Bb matches the "b" in "goober", but there is no match for any numeric characters in "book |
" | . Equivalent to [0-9]. | d matches "3" in "C3PO" and "2" in "apartment 2G" |
DAny | non-numeric character. Equivalent to [^0-9]. | D matches "S" in "900S" and "Q" in "Q45" |
f | formfeed character. | |
nNewline | character. | |
rCarriage | return character. | |
sAny | single whitespace character, including space, tab, form feed, or newline character. |
sbook matches "book" in "blue book", but there is no match for | any single non-whitespace character |
in "notebook" |
. Sbook matches "book" in "notebook", but there is no match in "blue book" |
ttab | . | |
wAny | alphanumeric character, including underscore. Equivalent to [A-Za-z0-9_]. | bw* matches "barking" in "the barking dog" and "big" and "black" in "the big black dog" |
WAny | non-alphanumeric character. Equivalent to [^A-Za-z0-9_]. | W matches "Jake&Mattie" |