(\d\d-\w\w\w-)(\d\d)
$120$2
^(\d+).+
^(\d{4})$
Character |
Function |
Example |
| |
Or Matches either the expression before or the expression after | |
gray|grey matches either “gray” or “grey” |
( ) |
Grouping |
gray|grey and gr(a|e)y both match “gray” or “grey” |
[ ] |
Matches a single character that is contained within the brackets |
[abc] matches “a”, “b”, or “c”gr[ae]y matches “gray” or “grey”, but not “graey”, “graay”, etc.[a-z] specifies a range which matches any lowercase letterfrom “a” to “z” [abcx-z] matches “a”, “b”, “c”, “x”, “y”, or “z”[hc]at [hc]at matches “hat" and “cat”[a.c] matches only “a”, “.”, or “c” |
[^ ] |
Matches a single character that is not contained within the brackets |
[^abc] matches any character other than “a”, “b”, or “c”[^a-z] matches any character that is not a lowercase letterfrom “a” to “z” [^b]at matches all strings matched by .at except “bat”q[^x] matches “qu” in “question”. It does not match “Iraq” since there is no character after the q for the negated character class to match |
{n} |
Preceding item is matched exactly n times |
a{3} matches only “aaa”[1-9][0-9]{3} matches a number between 1000 and 9999 |
{min,} |
Preceding item is matched min or more times |
a{3,} matches “aaa”, “aaaa”, “aaaaa”, “aaaaaa”, etc.a{3,5} matches “aaa”, “aaaa” and “aaaaa” |
{min,max} |
Preceding item is matched at least min times, but not more than max times |
a{3,5} matches only “aaa”, “aaaa” and “aaaaa”.[1-9][0-9]{2,4} matches a number between 100 and 99999 |
. |
Matches any character |
a.c matches “abc”, “acc”, “adc”, etc.gr.y matches “gray”, “grey”, “gr%y”.at matches any three-character string ending with “at”, including “hat”, “cat”, and “bat” |
? |
Matches the preceding character zero or one times |
ab?c matches “ac”, “abc”colou?r matches “color” and “colour”[hc]?at matches “hat”, “cat”, and “at” |
* |
Matches the preceding character zero or more times |
ab*c matches “ac”, “abc”, “abbc”, “abbbc”, etc.s.* matches “s” followed by zero or more characters, for example: “s” and “saw” and “seed”[hc]*at matches “hat”, “cat”, “hhat”, “chat”, “hcat”, “cchchat”, “at”, etc. |
+ |
Matches the preceding character one or more times |
ab+c matches “abc”, “abbc”, “abbbc”, but not “ac”[hc]+at matches “hat”, “cat”, “hhat”, “chat”, “hcat”, “cchchat”, etc. but not “at” |
^ |
Anchors the starting position in a string |
^[hc]at matches “hat” and “cat”, but only at the beginning of the string |
$ |
Anchors the ending position in a string |
[hc]at$ matches “hat” and “cat”, but only at the end of the string |
\ |
Escaped Treats the escaped character as a literal rather than a regex command |
\[.\] matches any single character surrounded by “[” and “]” since the brackets are escaped, for example: “[a]” and “[b]”1\+1=2 matches “1+1=2” |
Character |
Function |
\d |
Any digit |
\D |
Not a digit |
\w |
Any word character (Alphahnumeric characters, plus the underscore “_”) |
\W |
Not a word character |
\s |
Whitespace character (tab, carriage return, space, etc.) |
\S |
Not a whitespace |
\A |
First character in a string |
\z |
Last character in a string |
\u |
Uppercase letters |
\l |
Lowercase letters |
\p |
Visible characters and the space character |
\b |
Word boundaries |
\B |
Non-word boundaries |
Character |
Function |
x |
The character x |
\\ |
The backslash character |
\t |
The tab character |
\r |
The carriage-return character |
\e |
The escape character |