Some entities need to match patterns rather than specific terms. For example, national identification numbers, IDs, license plates, and so on. With regexp entities, you can provide regular expressions for matching.
Compound regular expressions
Each regexp entity corresponds to a single pattern,
but you can provide multiple regular expressions
if they all represent variations of a single pattern.
During agent training, all regular expressions of a single entity are combined
with the alternation operator (
|) to form one compound regular expression.
For example, if you provide the following regular expressions for a phone number:
The compound regular expression becomes:
The ordering of regular expressions matters. Each of the regular expressions in the compound regular expression are processed in order. Searching stops once a valid match is found. For example, for an end user expression of "Seattle":
Special handling for speech recognition
If your agent uses speech recognition (also known as audio input, speech-to-text, or STT), your regular expressions will need special handling when matching letters and numbers. A spoken end-user utterance is first processed by the speech recognizer before entities are matched. When an utterance contains a series of letters or numbers, the recognizer may pad each character with spaces. In addition, the recognizer may interpret digits in word form. For example, an end-user utterance of "My ID is 123" may be recognized as any of the following:
- "My ID is 123"
- "My ID is 1 2 3"
- "My ID is one two three"
To accommodate three digit numbers, you could use the following regular expressions:
\d \d \d
(zero|one|two|three|four|five|six|seven|eight|nine) (zero|one|two|three|four|five|six|seven|eight|nine) (zero|one|two|three|four|five|six|seven|eight|nine)
Create a regexp entity
- Open the Dialogflow CX Console.
- Choose your GCP project.
- Select your agent.
- Select the Manage tab.
- Click Entity Types.
- Click Create.
- Check Regexp entities.
- Complete remaining fields.
- Click Save.
EntityType.kind field to
Select a protocol and version for the EntityType reference:
|REST||EntityType resource||EntityType resource|
|RPC||EntityType interface||EntityType interface|
|C#||Not available||Not available|
|Go||Not available||Not available|
|PHP||Not available||Not available|
|Ruby||Not available||Not available|
The following limitations apply:
- Fuzzy matching cannot be enabled for regexp entities. These features are mutually exclusive.
- Each agent can have a maximum of 50 regexp entities.
- The compound regular expression for an entity has a maximum length of 1024 characters.