Regular Expressions/Patterns

2 minute read

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 triggers to find a matching one. Once the corresponding trigger is found, the virtual assistant will respond with the configured answer. If no triggers are matched, it will then search for trained FAQ examples, and if still nothing matches the pattern, it will provide a fallback response, such as 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 Trigger tab within the Editor dashboard.

  1. Click “Add New Content”
  2. Fill in the Trigger 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 “Save”

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: https://regexr.com/ in the dashboard, you can also try out add the ” Add positive test ” boxes.

lesson image

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.

lesson image
For more information about this article, please reach out to us at cspm@keyreply.com

Editor