sgn
sgn

Reputation: 65

Why regex does not work in karate framework?

I have a problem with regex in karate framework. I have a step:

And match each response.games[*].Price.value == '#regex \'\\d*.\\d{2}\''

All the time I get message :

assertion failed: path: $[0], actual: '183.26', expected: '#regex '\d*.\d{2}'', reason: regex match failed

Can anyone help me please? Where is the problem?

Upvotes: 2

Views: 3809

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626896

You may use

'#regex^[0-9]*[.]?[0-9]{2}$'

Here, #regex is part of the syntax to enforce regex validation, and the rest is the pattern that matches

  • ^ - start of string
  • [0-9]* - 0+ digits
  • [.]? - an optional period
  • [0-9]{2} - two digits
  • $ - end of string.

Upvotes: 4

Related Questions