Knowledge Center next icon Guide to Regular Expressions
Sep 28, 2022
3 minutes read

Guide to Regular Expressions

Expression entities are entities that consist of a regular expression, as opposed to one or multiple (compound) words. Regular expressions (Regex) are a sequence of characters that match a pattern in a piece of text. They make it possible to react to user input (e.g. a question) containing a specific sequence such as a postal code or tracking number; basically, any input that is variable and cannot be captured in a single word (without adding all the possible variations).

Regex has precedence over regular entities and will override the normalization process. This means that any input matching that regex will not be normalized, so make sure that your regex is as specific as possible, so they don't interfere with regular recognition in your project.

A great example of an expression type entity would be an entity that aims to capture a 5-digit postal code when provided. Because the amount of postal codes is extensive, it’s impossible to capture all possible variations in a regular entity (as this would involve adding countless words in the form of postal codes in an entity). What all postal codes do have in common, is their format. This makes them a perfect fit for being captured through an expression entity. Let’s create an expression entity to capture postal codes.

image.png

Create & Edit Regular Expression

Before you start creating regular expressions in Conversational AI Cloud, it’s good to know that they use case-insensitive matching and that they are validated and run using the ECMAScript standard. 

We’re going to add a regular expression that will recognize a Dutch postal code from the end user’s input. 

Follow these steps to create an expression type entity:

  1. Go to the Entities editor and click the add icon “+ “. 
  2. Select Create expression from the drop-down list
  3. Add a name and description for your regular expression
  4. Insert the expression, for  postal code: “[1-9]\d{3}\s?[a-zA-Z]{2} ”
  5. Click Save

If you have any questions that match with the regular expression that you just created, they'll show underneath.

5542-cm-create-expression.gif

Disclaimer:

After creating or editing your expression entity, the system will run it through your project's content. Should it find a match, it’ll link the entity to the question similar to how standard entities work. As expression entities allow for very broad recognition when defined poorly, this may have a negative effect on your recognition. If you’re unsure about the inner workings of regular expressions, make sure to take a look at some of the following external resources:

Test Regular Expressions

When you've created a new regular expression entity, be sure to test it and make sure it is being recognized properly. Regular expressions override Conversational AI Cloud's normalization process, enabling you to fine-tune your recognition. However, if your project is using multiple regular expressions, it is possible for them to conflict with one another.

Regular expressions in Conversational AI Cloud use case-insensitive matching and are compliant with the ECMAScript standard, which JavaScript is based on.

You can test your regular expressions at regex101.com. Be sure to select ECMAScript as your flavor before testing the code.

If you have tested the code and it still doesn't work in Conversational AI Cloud, please send a ticket to Support.

group icon
Get support

Can’t find the answer you are looking for?
Ask for the help of our chatbot, or get in touch with our support team.

Contact Support
Is this region a better fit for you?
Go
close icon