Regular expression quick start guide
From TBwiki
(Difference between revisions)
Ka-Lok Yeung (Talk | contribs) |
|||
Line 3: | Line 3: | ||
<tr><td>^</td><td>Matches beginning of a line</td></tr> | <tr><td>^</td><td>Matches beginning of a line</td></tr> | ||
<tr><td>$</td><td>Matches the end of a line</td></tr> | <tr><td>$</td><td>Matches the end of a line</td></tr> | ||
+ | <tr><td>\d</td><td>Matches a digit</td></tr> | ||
<tr><td>[characters]</td><td>Matches any single character between the brackets</td></tr> | <tr><td>[characters]</td><td>Matches any single character between the brackets</td></tr> | ||
<tr><td>re1|re2</td><td>Match either re1 or re2</td></tr> | <tr><td>re1|re2</td><td>Match either re1 or re2</td></tr> |
Revision as of 01:30, 15 September 2009
Regular Expression Pattern | Explanations |
---|---|
^ | Matches beginning of a line |
$ | Matches the end of a line |
\d | Matches a digit |
[characters] | Matches any single character between the brackets |
re1|re2 | Match either re1 or re2 |
re* | Matches zero or more occurrences of re |
re+ | Matches one or more occurrences of re |
re? | Matches zero or one occurrences of re |
Re{m,n} | Matches at least “m” and at most “n” occurrences of re |
(...) | Parentheses are used to group regular expressions |
\0, \1, \2, ... | Substitute the value matched by the nth grouped sub-expression, used in remapped fields. |
Here are some examples:
Add 2720 prefix:
/(\d+)/2720\1/
or
/([0-9]*)/2720\1/
Strip first 4 digits:
/([0-9]{4})([0-9]*)/\2/