转载自:http://www.regexlib.com/cheatsheet.htm?AspxAutoDetectCookieSupport=1
Metacharacters Defined
|
| MChar | Definition |
| ^ |
Start of a string. |
| $ |
End of a string. |
| . |
Any character (except
newline) |
| | |
Alternation. |
| {...} |
Explicit quantifier notation. |
| [...] |
Explicit set of characters to match. |
| (...) |
Logical grouping of part of an expression. |
| * |
0 or more of previous expression. |
| + |
1 or more of previous expression. |
| ? |
0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string. |
|
Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below. |
Metacharacter Examples
|
| Pattern | Sample Matches |
| ^abc |
abc, abcdefg, abc123, ... |
| abc$ |
abc, endsinabc, 123abc, ... |
| a.c |
abc, aac, acc, adc, aec, ... |
| bill|ted |
ted, bill |
| ab{2}c |
abbc |
| a[bB]c |
abc, aBc |
| (abc){2} |
abcabc |
| ab*c |
ac, abc, abbc, abbbc, ... |
| ab+c |
abc, abbc, abbbc, ... |
| ab?c |
ac, abc |
| asc |
a c |
|
|
| Escaped Char | Description |
| ordinary characters |
Characters other than . $ ^ { [ ( | ) ] } * + ? match themselves. |
| a |
Matches a bell (alarm) u0007. |
|
Matches a backspace u0008 if in a []; otherwise matches a word boundary (between w and W characters). |
| |
Matches a tab u0009. |
|
|
Matches a carriage return u000D. |
| v |
Matches a vertical tab u000B. |
| f |
Matches a form feed u000C. |
|
|
Matches a new line u000A. |
| e |
Matches an escape u001B. |
|