1

Good day Guys,

Please how can i perform case-insensitive matching on text that i read from the user input? i noticed that this code snippet

"context": {
         "number_extract": "<? input.text.extract('my name is ([\\w\\s\\w]*)', 1) ?>"
       }

will not match if the user enters My name is .......

Also please can anyone also suggest a good resource that i can use for using regular expression in the Dialog screen.

Thank you very much.

user980643
  • 113
  • 2
  • 8

1 Answers1

3

Watson conversation supports SPEL https://www.ibm.com/watson/developercloud/doc/conversation/expression-language.html

For regex you can do

input.text.matches( '[0-9]+' )

I didnt check but you can probably do

input.text.equalsIgnoreCase( 'xxxxx' )

You can also do

input.text.toUpperCase().matches(YOUR_REGEX)

Finally You can use the following (?i) for case insensitivity. See https://blogs.oracle.com/xuemingshen/entry/case_insensitive_matching_in_java

Dudi
  • 2,340
  • 1
  • 24
  • 39
  • Ok i will have a look at that URL. But if you look at my code sample you will see that am retrieving the name is the case match exactly as i have typed it, that is in small letters. But i will update shortly if this worked. – user980643 Feb 05 '17 at 16:25
  • also added toUpperCase option... though I really think you oughta reconsider your line of thinking, since its gonna be hard for you to extract the user name if they answer it slightly differently – Dudi Feb 05 '17 at 20:51
  • I cant get the equalsIgnoreCase to work because am not really interested in doing a matching, it is the extraction that is my issue. If you check the code sample in my original post i am trying to retrieve whatever is after the **my name is** the problem is how can i make this text case insensitive. – user980643 Feb 06 '17 at 10:24
  • Ok but what other options do you think that i should use? because am not very conversant with the best way to go about the setup yet, still learning. – user980643 Feb 06 '17 at 10:25
  • Just say: "Please specify your first and last name". Or any other direct and less open ended approach. If you really into parsing for the name. You should try to match the content to one of those name data stores. But this is not robust enough. – Dudi Feb 06 '17 at 10:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134966/discussion-between-dudi-and-user980643). – Dudi Feb 06 '17 at 12:11