---
sourceDocument: Xanadu Enable AI
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/intelligent-experiences

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu Enable AI

ft:clusterId :

    - platai

bundleId :

    - platai

workflow :

    - Platform


---

# Using regular expressions in entities

# Using regular expressions in entities {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

Learn how to use regular expressions in your NLU entities to establish patterns that help the system locate, match, and manage text.

Pattern entities use regular expressions (regex) to match any pattern of text, such as the
format of an email address, a phone number, or an incident or case ID.  
Note:  
ServiceNow uses and supports Java regex exclusively and not other vendor options, such as Perl regex.

## Regex examples {#using-regular-expressions-nlu__section_bfz_fbx_nhb}

For a full example of regex code used in a pattern entity, see [Create a pattern entity](https://servicenow-prod.fluidtopics.net/R06p7nAAw5pbg~ybFCp32Q "Create a pattern entity from a word or phrase with repeatable patterns, such as email addresses and phone numbers. These patterns help the system to recognize similar utterances based on the patterns.").

The following four examples provide the format and regex code for different pattern
entities.  

Knowledge base article
:   ServiceNow Knowledge Base (KB) articles use the format KB1234567. The
    regex code is KB\\d{7}, where KB = knowledge base record and
    d{7} = 7 digits.

Case number
:   Case tasks use the format CS1234567. The regex code is
    CS\\d{7} where CS = case record and d{7} = 7
    digits.

Email address
:   Email addresses use the format name@servicenow.com. The regex code is
    \\b\[a-zA-Z0-9\&\*/_.+-\]+@\[a-zA-Z0-9-\]+\\.\[a-zA-Z0-9-.\]+\\b, which
    supports these formats: name@servicenow.com and
    name@servicenow.co.in.

Phone number
:   United States phone numbers use the format 555-123-4567. The regex code
    is \\d{10}\|(?:\\d{3}-){2}\\d{4}\|\\(\\d{3}\\)\\d{3}-?\\d{4}, which supports these
    formats: 5108882062,510-888-2062, and
    (510)888-2062.

## Regex resources {#using-regular-expressions-nlu__section_rbt_dtd_b3b}

For further information on regular expressions, see the following external links.

* [Java Regular Expressions](https://www.tutorialspoint.com/java/java_regular_expressions.htm)
* [Java Regular Expression Tester](https://www.freeformatter.com/java-regex-tester.html#documentation)
* [Pattern (Java Platform SE7)](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)
* [Java regex match abbreviations](https://blog.softhints.com/java-regex-extract-abbriviations/)
{#using-regular-expressions-nlu__ul_tkw_5vr_b3b}
**Related tasks**   

* [Create a simple entity](https://servicenow-prod.fluidtopics.net/N~5DJDKjarceXuhwMKE6fg "Create one or more simple entities from words in your utterance examples. An entity is an object of, or context for, an action.")
* [Create a mapped entity](https://servicenow-prod.fluidtopics.net/L36lfvGw3Fx2eblSAc6lRA "Create an entity mapped to a vocabulary source, or to a list of values you manually create for the entity. Mapped entities can help provide multiple values the model can use as context when interpreting utterances.")
* [Create a pattern entity](https://servicenow-prod.fluidtopics.net/R06p7nAAw5pbg~ybFCp32Q "Create a pattern entity from a word or phrase with repeatable patterns, such as email addresses and phone numbers. These patterns help the system to recognize similar utterances based on the patterns.")
* [Create a system-derived entity](https://servicenow-prod.fluidtopics.net/L1zE3lTZQATqQxa52hzljg "Create a custom entity that's derived from a default system entity such as date, time, duration, or location.")
* [Create an open-ended entity](https://servicenow-prod.fluidtopics.net/ZSZ60xAPMEW~bNeORY2HfA "Use an open-ended entity when you want to improve intent prediction accuracy. Open-ended entities help your model focus on the context of the utterances.")
* [Import entities](https://servicenow-prod.fluidtopics.net/iz1K~UJviKCvsN2yRoYoCQ "Reuse entities that you have created across your other Natural Language Understanding (NLU) models. Importing entities saves time and helps improve the intents in your model.")

