Character | Description | Example | Example Meaning |
---|---|---|---|
^ | • Beginning of a line or string • Negation, inside a character class [ ] | • /^ABC/ • /[^ABC]D/ | • Matches ABC at the beginning of a line or string. • Matches any character before D except A or B or C. |
$ | End of a line or string | /ABC$/ | Matches ABC at the end of a line or string. |
. | Any single character | /^...$/ | Matches any three letter word. |
+ | One or more | /AB+/ | Matches one or more B characters after A (AB, ABB, ABBB, ...). |
* | Zero or more | /AB*/ | Matches zero or more B characters after A (A, AB, ABB, ABBB, ...). |
? | Zero or one | /AB?/ | Matches zero or one B character after A (A, AB). |
| | Alternation | /ABC|DEF/ | Matches ABC or DEF. |
\ | Literal character | /\$50\.00/ | Literally matches the string $50.00, negates the effects of the meta characters, $ and . |
/ | Boundary of regular expression | /ABC/ | Matches any line with ABC. Forward slash shows beginning and end of regular expression. |
[ ] | Character class | /[0-9]/ | Matches any digit. |
- | Range | /[0-9][A-Z]/ | Matches any digit followed by any capitol letter. |
( ) | Grouping | /(bob)*by/ | Matches zero or more of the group ‘bob’ before b (by, bobby, bobbobby, bobbobbobby, ...). |