Extract alphanumeric strings in an intent

705 views
Skip to first unread message

Kevin MacDermid

unread,
Dec 10, 2020, 2:40:07 PM12/10/20
to Dialogflow CX Edition users
I've been digging around a bit and I can't figure out how to extract alphanumeric strings in intents as entities. In my case users are likely to give me a model or part number that is a combination of characters and digits.
I tried detecting them using a regex like '\w*\d+\w*', but in most cases I get an error in the entity interface that says that the Regex is too broad. I guess I could do a similar regex in a Webhook but that seems like kind of a nasty workaround. Is there a proper way to handle that sort of entity?

Axel Eduardo Murillo

unread,
Feb 2, 2021, 12:08:35 PM2/2/21
to Dialogflow CX Edition users

With Regex Entities, you can extract your intended alphanumeric values using the following: 

  1. Set your regex entity entry to ‘\s\w*\d+\w*\s‘. 

  2. Add your regex to an intent’s training phrase:

    1. Example: image-1.png

If you wish to capture the regex on a form parameter, use the following:

  1. Set your regex entity entry to ‘^\w*\d+\w*$’.

  2. Set up your agent to prompt the user into entering only the alphanumeric value:

    1. Example: image-2.png

For similar regex entries, please utilize the ‘^’ and ‘$’ specifiers. These make it clear that the entity is to be checking if the whole query matches, and sufficiently resolves the “regex is too broad” error. 

You can add both ‘\s\w*\d+\w*\s‘ and ‘^\w*\d+\w*$’ as entries to the EntityType to cover both situations. Be sure to check the Dialogflow documentation for further tips. You can also check the Regular Expression Syntax documentation.
Reply all
Reply to author
Forward
0 new messages