-1

I'm testing a web service using karate framework using IntelliJ.

By framework definition, I should be able to use regex to assert XML responses and I have been able to use it to some extent.

But the problem arises when I want to assert using regex which contains back-slash, for example: "\X{20,}" So I tried: (using 3 back-slashes \\\)

Then match response ...... rawData == '#regex \\\X{20,}'

screenshot of Gherkin code

and this gives me an error:

com.intuit.karate.exception.KarateException: Illegal/unsupported escape sequence near index 1 \X{20,}

tuomastik
  • 4,559
  • 5
  • 36
  • 48
marelc
  • 63
  • 1
  • 9
  • 1
    A literal backslash in a Java regex context is actually _four_ backslashes in a row. Basically, two backslashes gives you a literal backlash, which itself in turn needs to be escaped again. – Tim Biegeleisen Aug 23 '18 at 05:34

1 Answers1

0

The regex \\\X{20,} cannot be valid. Double backslash is required in your feature file.

So \\ represents a single regex backslash (meant to escape what follows it). If you want to match a single literal \ in your regex, you need \\\\ in the feature file.

So your pattern should probably be \\\\X{20,} if the content should contain a backslash.

This is documented here.

Note that regex escaping has to be done with a double back-slash - for e.g: '#regex a\.dot' will match 'a.dot'

ernest_k
  • 44,416
  • 5
  • 53
  • 99