1

I am dealing with IBM Watson Conversation. I have a text that contains few letters and digits i.e. age is 26.

I have written a regex to match the digits from the text. It is done using .*?[0-9]+.*?. Now, I want those matched digits into context variables.

How to place the matched digits into context variable ?

When my condition matches with having input.text.matches('.*?[0-9]+.*?'), then I want to place only digits to my context variable.

For Ex:

{
    "context": {
               "digit": { input.text } 
    }
}

Here input.text takes the whole text and places it into digit variable.

How to place only digits by applying regular expression on text ?

iNikkz
  • 3,729
  • 5
  • 29
  • 59

2 Answers2

0

You can extract regular expressions from input text as follows:

input.text.extract('.*?([0-9]+).*?', 1)

The first part is your regular expression. The second parameter is the group ID.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
0

The second parameter is required for the extraction to work, so if we want to extract the whole matched substring, we use 0 for the extract_id as follows:

input.text.extract('[0-9]+', 0)
Tan Dat
  • 79
  • 1
  • 3