A string of characters that creates a search pattern is known as a RegEx or Regular Expression. RegEx can be used to determine whether a string includes a given search pattern. You can configure the dialogs in the Freshchat bot builder to only accept a specific response pattern.

For example, if you're building a chatbot to collect flight booking information, you can use RegEx to validate the passenger name record (PNR), an alphanumeric string of six characters. By setting up a RegEx pattern in the chatbot builder, you can ensure your customers enters a valid PNR and prevent errors or misunderstandings.

  • Navigate to the specific bot flow where you want to validate a string based on the RegEx.

  • Add a dialog, enter the content for the dialog, and select Custom as the input type.

  • For our example, the bot should only accept strings containing only six alphanumeric characters. The RegEx would be ^[a-zA-Z0-9]{6}$

  • Here's what it'll look like once you're done:

Note: Here's how this RegEx can be broken down

^ : Matches the start of the string

[a-zA-Z0-9] : Matches any alphanumeric character (letters or numbers)

{6} : Matches exactly 6 instances of the previous match (alphanumeric character)

$ : Matches the end of the string

Alternatively, you can ask Freddy to generate the RegEx for you using a simple text prompt. This is how it will work for the above example.

Here are a few more examples of RegEx for some familiar strings:

  • Social Security Number - ^\d{3}-\d{2}-\d{4}$
  • Validate a zip code in the United States (ZIP+4 format) - ^\d{5}(-\d{4})?$ 
  • An order that always starts with ABC followed by 4 digits - ^ABC\d{4}$
  • An email address in the "freshworks.com" domain - ^[a-zA-Z0-9._%+-]+@freshworks\.com$
  • An eight-character string that contains only alphanumeric characters - ^[a-zA-Z0-9]{8}$