Tip – Consider using Words instead of RegEx
Words is another text-matching Condition method that doesn’t require technical knowledge to understand and implement. In many cases, Words can replace RegEx. For example, suppose you’re attempting to route Spanish language requests to a Spanish Inbox which usually contains the words “Gracias,” “Hola,” and “Orden.” Using Words can detect and route those requests to your Spanish Inbox without needing RegEx.
Regular Expressions (RegEx) extract information from text by searching for matches of a specific search pattern. In Rules and People Match Boosts, RegEx helps distinguish words that could be part of other words. This is particularly useful to indicate words that can be part of different words, like “ask” to match phrases that may have variable text.
Using ask as an example, ask is contained in basketball and task, but sometimes, you may only want a Rule or boost to fire if the Customer says “can I ask you something” and not fire if they say “I want to buy a gift basket.
RegEx is a popular method for detecting spam inbound communications via Rules (by detecting specific spam keywords in an email), applying spam Topic, and closing the Conversation so Agents are not bothered by spam communications. RegEx matching in Gladly uses Google’s re2 library .
RegEx syntax #
Before you begin using RegEx, it’s essential to have basic knowledge of RegEx syntax. Read this tutorial
You can also complete a free Regex 101 eLearning course
RegEx examples #
Once you have a basic understanding of Regex syntax, review examples of regular expressions
For example, the image below shows RegEx (?i)(\W|^)(baloney|darn|drat|fooey|gosh\sdarnit|heck)(\W|$) is used to match any word or phrase containing the words “baloney, darn, drat, fooey, gosh darnit, and heck.”
Numerals as RegEx #
In addition to Words, RegEx syntax may also be set up to account for numerals. Matching order number structures or sequences is a common use case for leveraging numerals in RegEx. Let’s use Sidekick as an example to look up exact order numbers using RegEx.
In Sidekick, looking up an order is a hard-coded check that considers a breadth of order number structures, but is not comprehensive. A digit string such as a phone number or zip code may be interpreted as an order number. Utilizing RegEx can help circumvent this potential issue, as it gives the ability to specify the expected order number formula.
When working with RegEx in Sidekick and configuring a Thread, adding the Ask Order Number Regex Sub-Action within the Look Up Order Action will ensure that the order number found matches the defined RegEx pattern.
Let’s consider an example order number structure, A1z009457, where:
- The order number always begins with 2-3 uppercase and/or lowercase alphanumeric characters (A1z in this example).
- The order number always contains 5-8 digits following the alphanumeric prefix (009457 in this example).
The RegEx pattern for example order number structure A1z009457 could look like: ^[A-Za-z0-9]{2,3}\d{5,8}$
This pattern would match any order number with the following structure:
- Order numbers beginning with 2-3 alphanumeric characters. This can include both uppercase and lowercase letters, as well as digits.
- Order numbers followed by 5-8 digits.
Here’s a breakdown of the pattern components:
^
asserts the start of the string.[A-Za-z0-9]{2,3}
matches the beginning of the string with 2 to 3 alphanumeric characters.\\d{5,8}
matches 5 to 8 digits.$
asserts the end of the string.
Examples of additional order numbers that match:
- AB12345 (2 letters + 5 digits)
- A1b678901 (3 multi-case alphanumeric characters + 6 digits)
Examples of order numbers that do not match:
- 9A1234 (2 alphanumeric characters + 4 digits) – This does not match as it only includes 4 digits.
- 45890 (5 digits) – This does not match as it does not start with with 2 to 3 alphanumeric characters.
RegEx tools #
You can validate RegEx before saving them for use in Rules or People Match Boosts by using tools like Rubular