---
schema_version: "1"
id: 3879a5001d660d62a74e04eb206bb3082a7bad35ea1b31238927ecead375679d
title: REGEX
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/customize_functions_regex.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.customize_functions_regex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 859ff7651e5b83432e72e952dea5cc0273b5f075956e116fddf3aaa526b6d675
description: Compares a text field to a regular expression and returns TRUE if there is a match. Otherwise, returns FALSE.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# 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](http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html). 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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_example.png)

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}")
 )
)
```