Common Regular Expression Patterns
This section contains a list of commonly used regular expressions that can be used to identify or format data. This list is provided as an introduction to regular expressions. These and other patterns can be modified to suit your needs.
Note: The regular expressions below will work in many situations. However, the pattern you are trying to match may have extra white spaces, variations, or similar patterns that need to be accounted for. Always test your regular expressions on a variety of data and edit them as needed so that they only return the results you want, especially if you are using regular expressions with using the Pattern Matching activity in Workflow.
Examples of Common Regular Expressions
The following table contains a list of common patterns that can be used to restrict field data, provided only as an introduction to the many uses of regular expressions to ensure proper data formatting.
| Type | Pattern | Example |
|---|---|---|
|
Phone number ((xxx) xxx-xxxx format) |
\(\d{3}\) \d{3}-?\d{4} |
(562) 988-1688 |
|
Short date (single or double-digit month-day format) |
\d?\d/\d?\d/\d{4} | 12/25/2009 |
|
Social Security number (xxx-xx-xxxx) |
\d{3}-\d{2}-\d{4} | 123-45-6789 |
|
Time (h:mm or hh:mm format) |
[0-9]?[0-9]:[0-9][0-9] | 17:50 |
| ZIP code | \d{5}-\d{4}|\d{5} | 90807 or 92064-3404 |
|
ID or tracking number ("Tracking ID" followed by a colon, space, and any combination of letters or numbers) |
Tracking ID\:\s*(\w*)\s* | Tracking ID: 12KDF7Q89WFL |
|
Legal Land Description (Two possible formats. Both have the format two letters-two numbers-three numbers-two numbers. Then, the first allows a single digit at the end. The second allows a letter and digit at the end.) |
[A-Z]{2}-\d{2}-\d{3}-\d{2}-[A-Z]\d [A-Z]{2}-\d{2}-\d{3}-\d{2}-\d |
NW-03-042-12-W4 |
|
Last Name, First Name (Allows for hyphens in the last name, and underscores in both names.) |
([\w\-]+)\s*,\s*(\w+)\s* | Smith, Paul |
|
Fiscal Year (October through September of the next year) |
1[0-2]/\d?\d/2015|0?[1-9]/\d?\d/2016 | Returns a date between 10/01/2015 and 9/30/2016 |
|
Parent folder from a folder path (Finds everything after the last backslash in a string) |
([^/\\]*)$ |
From \My Documents\Sales\Contracts returns Contracts |
Examples of How to Retrieve a Single Line of Text
The following table shows regular expressions that retrieve a single line from multi-line data and can also be applied to restrict field values, helping ensure proper data formatting.
| Type | Pattern |
|---|---|
| First Line | ^[^\n]+ |
| Any specific line, where N is the line number. Line numbers are zero-based. E.g., the first line is numbered 0, the second line is numbered 1, etc. | (?:[^\n]*\n){N}(.+) |
| Last Line | [^\n]+$ |
Note: The First Line pattern will not return the desired results when the data being processed only contains a single line of text.