Loading
Salesforce Enforces New Security Requirements in Summer 2026Read More
Extend Salesforce with Clicks, Not Code
REGEX

REGEX

Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, returns FALSE.

A regular expression is a string used to describe a format of a string according to certain syntax rules.

Use

REGEX(text, regex_text) and replace text with the text field, and regex_text with the regular expression you want to match.

Tips

  • Regular expression syntax is based on Java Platform SE 6 syntax. However, backslash characters (\) must be changed to double backslashes (\\) because backslash is an escape character in Salesforce.
  • The Salesforce regular expression engine matches an entire string as opposed to searching for a match within a string. For example, if you are searching for the name Marc Benioff, use the regular expression, .*Marc Benioff.*, to find a match in a string like the following:
    According to Marc Benioff, the social enterprise increases customer success.
    If you use the regular expression, Marc Benioff, the only string that this regular expression matches is:
    Marc Benioff
  • Capture groups and substitutions are ignored.
  • This function is available everywhere formulas exist except formula fields and custom buttons and links.
Validation Rule Example
Validation Rule Example

This example ensures that a custom field called SSN matches a regular expression representing a valid social security number format of the form 999-99-9999.


NOT(
 OR(
  LEN (SSN__c) = 0,
  REGEX(SSN__c, "[0-9]{3}-[0-9]{2}-[0-9]{4}")
 )
)
 
Loading
Salesforce Help | Article