Regex Cheatsheet
Erol Toker avatar
Written by Erol Toker
Updated over a week ago

Introduction to Regex

Regular expressions are an incredibly powerful tool for analyzing and extracting data from text without writing code (similar to an Excel formula or Salesforce formula field). We highly recommend this tutorial to understand the basics.

Salesforce is built on Java, which implements Regex in a specific way. You should only use Regex testers built on Java like this.

Regex for Truly Generated Datasets

Capture Emailer FirstName

(?<=<)\w([^\s]+)

** Capture all alphabetical characters between ' <' and ' '

Capture Emailer Last Name

\s\w+(?=>)

** Capture all alphabetical characters between ' ' and '>'

Capture Email Address

[\s].*@([^\s]+)

** Capture all alphabetical characters between ' ' and '>'

Generic Regex Cheatsheet

US Phone Numbers

(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})

** This captures all common variations of 10-digit US phone numbers

Did this answer your question?