Example | Matches |
---|---|
[b-chm-pP]at|ot | bat, cat, hat, mat, nat, oat, pat, Pat, ot |
\d | 0,1,2,3,4,5,6,7,8,9 |
\d{5}(-\d{4})? | Matches a US zip code |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
“any string” | The string | word | word |
\d | Any digit from 0-9 | number:\d | number:5 |
\w | Any word character | \w\w | _Q |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
\s | Any whitespace character | \s | " " |
\t | Tab | T\t\w{2} | T ab |
\D, \W, \S | Any character that is not a digit, word character or whitespace character. | \D\W\S | s=2 |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
+ | One or more of the item stated before. | w+ | wwww |
{X} | Exactly X amount of times. | w{3} | www |
{X,Y} | Match X to Y amount of times. (greedy) | w{2,4} | wwww |
* | Zero or more times (greedy) | A*B*C* | AACCCCCC |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
+ | One or more times (greedy) | \d+ | 1234555 |
? | Once or none. / Makes quantifiers lazy | words? | words, word |
? | Once or none. / Makes quantifiers lazy | \w{2,4}? | ab in abcd |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
. | Any character except new line. | . | w |
.* | Any character any amount of times except new line. | .* | This is an entire line of text. |
\ | Escapes special characters for the purpose of matching. | \.{3} | … |
Regular Expression | Matches | Example | Sample |
---|---|---|---|
| | Or/alternating | 1{2}|2{2} | 11221122 or 11 or 22 |
(…) | Capturing groups. | (\d{3})\s\d{3}-\d{4} | 301 999-2222 (captures 301) |
[…] | One of the characters in the brackets. | T[ao]p | Tap or Top |
[…-…] | Indicates range. | [a-z] | One lowercase letter. |
[^x] | One character that is not x | [^a-z]{3} | A1! |
^ | Start of the string or line | ^abc.* | Abc (assuming that this is the beginning of the string |
$ | End of string or line | .*? the end$ | this is the end |