Common Regular Expression Patterns

This page contains a list of commonly used regular expressions. These and other patterns can be modified for your needs. Note that you should always test your regular expressions using the Pattern Matching activity on a variety of data and edit them as needed so that they only return the results you want.

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.

Common Regular Expressions
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/31/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 contains examples of regular expressions to retrieve a single line of text from data containing multiple lines of text:

Retrieving Single Line of Text
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 that the First Line pattern will not return the desired results when the data being processed only contains a single line of text.