Regular expression quick start guide

From TBwiki
(Difference between revisions)
Jump to: navigation, search
m (Added new regex)
m (moved Toolpack: Commonly Used Regular Expression Pattern to Regular expression quick start guide: Transform page to become a quick reference guide)

Revision as of 15:36, 26 January 2010

Regular Expression PatternExplanations
^Matches beginning of a line
$Matches the end of a line
\dMatches a digit
[characters]Matches any single character between the brackets
re1|re2Match 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/

Strip # and 7 first digits:

/([#])([0-9]{7})([0-9]*)/\3/

References

Personal tools