Regular expression quick start guide
From TBwiki
(Difference between revisions)
m (moved Toolpack: Commonly Used Regular Expression Pattern to Regular expression quick start guide: Transform page to become a quick reference guide) |
|||
Line 1: | Line 1: | ||
− | + | == Quick Reference Table<br> == | |
− | < | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Here are some examples: | + | {| cellpadding="2" border="1" |
+ | |- | ||
+ | ! align="left" width="250" | Regular Expression Pattern | ||
+ | ! align="left" | 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. | ||
+ | |} | ||
+ | |||
+ | <br> | ||
+ | |||
+ | == Quick References == | ||
+ | |||
+ | === Text Patterns and Matches<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Literal Characters<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Character Classes or Character Sets<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Shorthand Character Classes<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === The Dot Matches (Almost) Any Character<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Repetition<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Optional<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Anchors<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Alternation<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Grouping and Capturing Group<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | == Examples<br> == | ||
+ | |||
+ | Here are some examples: | ||
+ | |||
+ | Add 2720 prefix: | ||
− | |||
/(\d+)/2720\1/ | /(\d+)/2720\1/ | ||
− | or | + | |
+ | or | ||
+ | |||
/([0-9]*)/2720\1/ | /([0-9]*)/2720\1/ | ||
− | Strip first 4 digits: | + | Strip first 4 digits: |
+ | |||
/([0-9]{4})([0-9]*)/\2/ | /([0-9]{4})([0-9]*)/\2/ | ||
− | Strip # and 7 first digits: | + | Strip # and 7 first digits: |
+ | |||
/([#])([0-9]{7})([0-9]*)/\3/ | /([#])([0-9]{7})([0-9]*)/\3/ | ||
− | == References == | + | == Online Tools == |
+ | |||
+ | |||
+ | |||
+ | == References == | ||
− | * [[Toolpack: How to Use RegEx in Called and Calling Number Mask|How to Use RegEx in Called and Calling Number Mask]] | + | *[[Toolpack: How to Use RegEx in Called and Calling Number Mask|How to Use RegEx in Called and Calling Number Mask]] |
− | * [[Toolpack: How to Use RegEx in Remapped Called and Calling Number Mask|How to Use RegEx in Remapped Called and Calling Number Mask]] | + | *[[Toolpack: How to Use RegEx in Remapped Called and Calling Number Mask|How to Use RegEx in Remapped Called and Calling Number Mask]] |
Revision as of 17:17, 26 January 2010
Contents |
Quick Reference Table
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. |
Quick References
Text Patterns and Matches
Literal Characters
Character Classes or Character Sets
Shorthand Character Classes
The Dot Matches (Almost) Any Character
Repetition
Optional
Anchors
Alternation
Grouping and Capturing Group
Examples
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/