regex with optional character/class/group doesn't seem to work

149 Views Asked by At

Regex operator ? for optional character/class/group seems to fail. Karate version: 0.9.9.RC1

I tried to match a phone number with optional leading + sign against these, but fails to match

  • <number>#regex \+?\d{6,11}</number>
  • <number>#regex (\+)?\d{6,11}</number>
  • <number>#regex [\+]?\d{6,11}</number>

Here: https://github.com/intuit/karate#the-karate-object at karate.extract(text, regex, group), I read that regex follows the Java regex rules, so I checked my regex here to be sure I did not make a mistake (there are too many flavors of "standard" regexes):

https://www.freeformatter.com/java-regex-tester.html Here, all the above regexes work as expected for phone numbers with or without leading +.

Of course there is the alternative to use an alternative, but it is clumsy. This works within a karate match: <number>#regex \+\d{6,11}|\d{6,11}</number>

Did I do something wrong?

0

There are 0 best solutions below