Regular Expressions/ Patterns

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.
  5. The mobile number pattern in Singapore would be /(\+65 ?)?(6|8|9)\d{7}/i
  6. Click “Submit”

Here are some types of setup:

  1. /./i
  2. 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.
  3. /menu/i
  4. 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.
  5. /^menu$/i or /^(menu|main menu)$/i
  6. 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.
  7. [more advanced] /^(how a?re? (yo)?u).{0,2}$/i
  8. “?” 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: https://regexr.com/ 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