kmancusi
kmancusi

Reputation: 571

Karate #regex; unable to validate partial matches

I'm playing with Karate's #regex validation and running into an issue.

When I have a file like this pravda-text_field-OIQSNP, I am only looking to match the first part of the string and hyphen, in this case pravda-

Here is what my attempt looks like:

And match each $.items contains { filename: \\Apravda- } 
// I'm using double back-slashes for the escape char

When I run the test the assertion fails only saying "reason: regex match failed"

What am I doing wrong with my validation?

Upvotes: 2

Views: 1832

Answers (1)

Babu Sekaran
Babu Sekaran

Reputation: 4239

This should work,

And match data.items contains {filename : "#regex pravda-.+" }

#regex in karate supports only full match I believe,

so if you are writing a regex for matching make sure your entire string matches for the expression or at least escape the remaining string as it did above using .+

Upvotes: 4

Related Questions