Character | Meaning | Example | Matches |
. (period) | Any single character (except newline) | a.. | act, art, arc |
* (asterisk) | Zero or more repetitions of the preceding charcter/pattern | tel* | tel, tell, telll... |
\ (backslash) | Escapes a special character, making it literal | \. | Matches a period (.) |
^ (caret) | Beginning of a string | ^Or | Matches strings starting with "Once" |
$ (dollar sign) | End of a string | end | Matches string ending with "end" |
| [ ] (brackets) | Match any one character in the set | [Aa] | Matches a or A |
[^ ] | Negates the set (matches anything not listed) | [^0 | Matches any non-digit |
- (hyphen inside brackets) | Defines a range | [A-Z] | Matches any uppercase letter |
Repetition codes {} let you control how many times a pattern must appear:
Regex Pattern | Matches | Does NOT Match |
[0-9]{1,} | Whole numbers (1, 33, 23496187) | Non-numeric strings |
[0-9][0-9,]{3,} | Numbers ≥ 1,000 with/without commas (1,000, 1000, 999,999,999,999) | 10, 100, 999 |
| [0-9][0-9,]{1,}\.[0-9]{1,} | Numbers with decimals (10.0, 100.001, 1,234.567) | 123, 123., .001 |
[0-9]{1,}[ ][0-9]{1,}/[0-9]{1,} | Mixed number (3 1/2, 8 7/16, 2271 17/22) | 3/4, 1,000 1/2 |
[0-9]{1,}˚[ ]*[0-9]{1,}΄[ ]*[0-9]{1,} | Bearings (10˚ 17' 33", 10˚17'33") | 10˚ 17', 17' 33" |
[\+\-][0-9]{1,} | Signed whole number (-1, +1000, -100000) | -1,000, 1000 |
[xX]*[0-9A-Fa-f]{2,} | Hexadecimal (xF0, x00ff, 8010, abc, 0123456789aBcDeF) | F, 0, xyz |