Regular Expressions/Patterns

Updated on December 12, 2022

Regular Expressions are basically a string of varying letters or numbers that maintain a constant pattern regardless of circumstance.

How is this useful?

It is common for regular expressions to come up in conversations, whether it is to verify details or to collect information.  Enabling the virtual assistant to identify these patterns in a conversation is a smart and efficient way for the virtual assistant to understand the user’s intent.

How does this work?

If a user enters a regular expression, the virtual assistant will run through the list of entities to find a matching entity. Once the entity it belongs to is found, the virtual assistant will respond with the configured answer, or if no entities were matched, it will give a fallback response like asking the user to rephrase their question.

For example:

A user has an intention to update their personal details.

The user types “I want to update my mobile number to 91234567.”

From the pattern entered, the virtual assistant is able to detect that “91234567” is a mobile number, and that this means the user is attempting to update their personal particulars.

Steps to configuring regular expressions:

Navigate to the Entities dashboard.

  1. Click “Add Entity”
  2. Give a name to the group in “Entity Name”. In this example, it would be Mobile Number.
  3. Under Type, select “Pattern/Regex”
  4. Enter the pattern.
    The mobile number pattern in Singapore would be /(\+65 ?)?(6|8|9)\d{7}/i
  5. Click “Submit”

Here are some types of setup:

  1. /./i
    This is a catch-everything expression, and case insensitive (i.e. big or small letters do not matter). Please do not leave your trigger with this expression, unless you have added a condition or a context.
  2. /menu/i
    I replaced the “.” with a word “menu” here. This means that as long as there is a word “menu” detected (either keyword or in a sentence), this trigger will be activated.
  3. /^menu$/i or /^(menu|main menu)$/i
    I added “^” at the front and “$” at the back of my keyword(s). This means that only the keyword(s) defined in between these 2 symbols will be captured. Note that i separate 2 keywords with “|” sign. You may add-on more keywords, just add a “|” symbol in between them.
  4. [more advanced] /^(how a?re? (yo)?u).{0,2}$/i
    “?” represents optional. You can make a character or a group of characters (groups by round brackets) optional. The “.{0,2}” means that I can capture up to 2 characters after the expression defined. e.g. “how are you”, “how r u”, “how r u!!”

Feel free to try out here: in the dashboard, you can also try out add the ” Add positive test ” boxes.

Possible errors If you encounter errors in saving, it is most probably due to the regular expression matching a pattern that is recognized as a potential security threat. If that happens, you can do the following: 1) If you want to add something simple: Toggle to Simple Mode, click on + New Tag and type in the texts you want to detect 2) If you have more complex regular expressions, please contact us to help you investigate.

Screenshot 2020-12-17 at 11.33.44 AM
Did we help you?

Learn more about KeyReply

To see our Conversational AI in action, sign-up for a guided walk-through and see how our platform can be tailored for your organization’s needs