Search code examples
regexdialogflow-cx

DialogFlow CX throwing "Regular expression match too broad" error for REGEX ENTITIES


I try to define a DialogFlow CX custom entity for values like e.g. "0.23" using the Regex option and entering the following Regex: [+]?([.]\d+|\d+([.]\d+)?)

But DiglogFlow CX would not accept this Regex and throw the error Validate entity failed because of the following reasons: Regular expression match is too broad: [+]?([.]\d+|\d+([.]\d+)?)

I have this issue with many, many other Regex examples. Why can't I use Regex like the one above? This is not broad at all, right? This perfectly defines a very specific number format which I need. It seems I am somehow not understanding this all all...?!


Solution

  • The "Regular expression match is too broad." error occurs if the regular expression that you defined has a pattern that is not specific enough - which might result in it matching virtually anything or matching unlimited values with the same pattern.

    For example, your regular expression [+]?([.]\d+|\d+([.]\d+)?) can match multiple numbers with the sample pattern:

    • 2.34
    • 0.123 231.1231 .145 …

    For your use case, you may consider using the @sys.number system entity instead. The @sys.number matches any ordinal and cardinal numbers including decimals.

    However, if you prefer using a regular expression entity, you can use the one of the following syntax for accepting decimal numbers:

    • ^[+]?([.]\d+|\d+([.]\d+)?)$

      • ^ means beginning of text

      • $ means end of text

        Note: The ^ and $ symbols prevent the regular expression from matching unlimited values with the same pattern. Ex. 23.23 13.31 23.12 0.113 …

    • [0-9]*[.][0-9]+

      • [0-9]* means that it will match one or more digits from “0” to “9” or none
      • [.] means that it will only match “.”
      • [0-9]+ means that it will match one or more digits from “0” to “9”

    The syntax above will match these formats:

    • 0.23
    • .23
    • 123.4567

    Dialogflow uses the Google RE2 syntax for Regular Expression.