-1

I have a message send to DialogFlow, look like: I wanna go to <@U12A0GF233T> and I want DialogFlow can detect U12A0GF233T as an entity.
So I created an entity @place with value ^\<@([A-Z])\w+\>.
But when the message was recived, dialogFlow can not detect @place.
I tested my regex on https://regexr.com/, it's work, but it doesn't work on DialogFlow.
Did I make some mistake here?

  • Try using more words to describe what you need. – FSDford Oct 23 '20 at 06:00
  • 1
    The pattern `^\<@([A-Z])\w+\>` by itself does not match `U12A0GF233T` in `I wanna go to <@U12A0GF233T>` Try it like this `^[^<>]*<@([A-Z]\w+)>` https://regex101.com/r/ps3V7J/1 – The fourth bird Oct 23 '20 at 06:58
  • @Thefourthbird I made a mistake when I use regex pattern of Javascript for Python (^_^"). But with your pattern, when I test with `I want to move my home office to <@U12A0GF233T>` (for example). The result was returned is `office to <@U12A0GF233T>`. I change pattern to `^*<@([A-Z]\w+)>` and it's working. I dont know Python so I'm not sure this partern is true. But you saved me. Thank you so much. – Duy Hưng Androgyne Tenor Oct 23 '20 at 08:19
  • Maybe you just want `<@([A-Z]\w*)>`? – Wiktor Stribiżew Oct 23 '20 at 08:22
  • @DuyHưngAndrogyneTenor In that case, I think it should be `^<@([A-Z]\w+)>` instead of `^*<@([A-Z]\w+)>` – The fourth bird Oct 23 '20 at 08:54
  • @WiktorStribiżew and Thefourthbird: I try to change to them but did not work in my cases. – Duy Hưng Androgyne Tenor Oct 23 '20 at 09:02
  • @DuyHưngAndrogyneTenor Maybe you meant a dot before the asterix `^.*<@([A-Z]\w+)>` https://regex101.com/r/M2008Q/1 – The fourth bird Oct 23 '20 at 09:17
  • 1
    @Thefourthbird No, when I add `^.*<@([A-Z]\w+)>` to DialogFlow Entity value, it did not correctly detect the phrase `<@U12A0GF233T>`. When I use `^*<@([A-Z]\w+)>` and it detect correctly (at least for now in the cases that I have tried). Haha. I do not know why. – Duy Hưng Androgyne Tenor Oct 23 '20 at 09:53

1 Answers1

1

Basically Google Dialogflow leverages RE2 C++ library for the regular expressions associated with the entity, that might change slightly the general regexp dialect, just follow this RE2 Syntax page.

In the explained use case, I've finished up regexp pattern adjusting either with:

^*<@([A-Z]\w+)>

Or

\<@([A-Z]\w+)>

Nick_Kh
  • 5,089
  • 2
  • 10
  • 16