Perl Regular Expression Quick Reference 1.05.
Perl Regular Expression Tutorial.
C++ Boost.Regex library for Perl Regular Expression Syntax.
Perl Regular Expressions briefly:
\ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
*? Match 0 or more times
+? Match 1 or more times
?? Match 0 or 1 time
{n}? Match exactly n times
{n,}? Match at least n times
{n,m}? Match at least n but not more than m times
\t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)
\a alarm (bell) (BEL)
\e escape (think troff) (ESC)
\033 octal char (think of a PDP-11)
\x1B hex char
\c[ control char
\l lowercase next char (think vi)
\u uppercase next char (think vi)
\L lowercase till \E (think vi)
\U uppercase till \E (think vi)
\E end case modification (think vi)
\Q quote (disable) pattern metacharacters till \E
\w Match a "word" character (alphanumeric plus "_")
\W Match a non-word character
\s Match a whitespace character
\S Match a non-whitespace character
\d Match a digit character
\D Match a non-digit character
\b Match a word boundary
\B Match a non-(word boundary)
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
\G Match only where previous m//g left off (works only with /g)
Decoding Regular Expressions
| Symbol | What It Means | Example | What It Might Find |
|---|---|---|---|
| + | find 1 or more of preceding item | ta+ | ta, taa, taaa |
| * | find 0 or more of preceding item | ba* | b, ba, baa, baaa |
| ? | preceding item is optional | ab?c | abc, ac |
| . | match any character (except return) | 1.2 | 1 2, 122, 1d2, 1$2 |
| [^x] | match any character except x | us[^a] | usb, usc, usd, use |
| [0-9] | match any digit | 9021[0-9] | 90210 through 90219 |
| ^ | match start of line | ^hello | matches hello only at beginning of line |
| $ | match end of line | end$ | matches end only at end of line |
| ( ) | group items together | (ab)+ | ab, abab, ababab |

Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου