The following is a list of characters that are commonly used in regular expressions.
Character |
Description |
---|---|
\d |
Matches any numeric character |
\D |
Matches any non-numeric character |
\s |
Matches any white space character (including Tab and Alt characters, ASCII 32 and lower) |
\S |
Matches any non-white space character |
\w |
Matches any word character (i.e., A-Z, 0-9, and _) |
\W |
Matches any non-word character |
* |
Denotes 0 or more instances of the preceding element |
+ |
Denotes 1 or more instances of the preceding element |
? |
Denotes 0 or 1 instance of the preceding element |
. |
Matches any single character (i.e., wildcard) |
^ |
Matches the starting position within the search string |
$ |
Matches the ending position within the search string |
[ ] |
Matches any single character included in the specified set of characters (e.g., [A-DF] or [ABCDF] would match A, B, C, D, or F) |
[^ ] |
Matches any single character not included in the specified set of characters (e.g., [^F] would match any character except F) |
( ) |
Denotes a logical grouping of part of an expression, as well as a SubMatch (e.g., if [A-Z]{3}\s(\d{3}) is matched against PSY 101, then 101 is the SubMatch) |
{ } |
Denotes the minimum and maximum match counts (e.g., in the string ABC1990, ABC\d{2,4} would match ABC19, ABC199, or ABC1990) |
| |
Separates alternate possibilities (e.g., Bob|Steve would match Bob or Steve) |
?: |
Denotes that the SubMatch it is contained within will not be stored (e.g., (abc)(?:defg)(123) would only have two SubMatches: abc and 123) |