Regular Expressions
Regular Expressions
Resources: See W3 Schools Tutorials for further information.
Common RegEx Characters
Character | Notes |
---|---|
? | 0 or 1 occurence of the preceding character |
+ | 1 or more occurences of the preceding character |
* | 0 or more occurences of the preceding character | \ | Escape character |
. | Any character except newline |
\d | Single numeral |
\w | Single character from a to Z, 0-9, or underscore |
\s | White space character |
| | Either or |
() | within a group |
Example 1: Find all instances of a lowercase word that may be in the singular or plural e.g. garden or gardens
gardens?
Example 2: Find all instances of words that differ by a specified character e.g. shot or shoot
shoo?t
Example 3: Find all instances of a phrase with noun variations e.g. I like …
I like (dogs|cats|rabbits)
Example 4: Find all instances of a positive integer of one or more of a digit e.g. 9, 99, or 999
9+
Example 5: Find all “double 0” agent codes e.g. 007, 008, 009
00\d
Example 6: Recognize standard format dates e.g. 03/22/1990
\d\d/\d\d/\d\d\d\d
Example 7: Find all instances of positive integers of different lengths that begin with the same known digits followed by unknown digits e.g. 007 or 0014
00\d+
Example 8: Find all instances of positive integers of different lengths that begin with the same known digits followed by zero or more unknown digits e.g. 00, 007 or 0014
00\d*
Example 9: Find all instances of a decimal number e.g. 22.17
\d\d\.\d\d