OiRc
OiRc

Reputation: 1622

How to trigger a node using email regex in Watson Conversation?

I am trying to extract an email address from user input text in Watson Conversation. First thing first, I need to trigger a particular node using an if condition like this:

input.text.contains('\^(([^<>()[].,;:s@\"]+(.[^<>()[].,;:s@\"]+)*)|(\".+\"))@(([[‌​0-9]{1,3}.[0-9]{1,3}‌​.[0-9]{1,3}.[0-9]{1,‌​3}])|(([a-zA-Z-0-9]+‌​.)+[a-zA-Z]{2,}))$\')

But it doesn't work, I tried a lot of regexes that I found on the internet but none of them work. Does anyone know how to write a proper regex?

Upvotes: 1

Views: 466

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627292

I suggest using a much simpler, approximate, regex to match emails that you need to use with String.matches(string regexp) method that accepts a regex:

input.text.matches('^\\S+@\\S+\\.\\S+$')

Do not forget to double escape backslashes so as to define literal backslashes in the pattern.

Pattern details:

  • ^ - start of string
  • \\S+ - one or more non-whitespace chars
  • @ - a @ symbol
  • \\S+ - one or more non-whitespace chars
  • \\. - a literal dot
  • \\S+ - one or more non-whitespace chars
  • $ - end of string.

Upvotes: 2

Related Questions