Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Postman test script match string with regex

Postman response is as below: '''{ "error" : "validation error at #/test/TC_1594792360026/test" }'''

I would like to verify this error message string. Digits are changed every time so I want to use it regex for that. I think regex [0-9]+ should work. But I don't know how to frame it in Postman.

I am using it in postman as below: str t = "validation error at #/test/[0-9]+/test";

pm.expect(t).match(jsonData.error)

and Postman throws an error as "TypeError: e.exec is not a function"

like image 232
Pratik Patel Avatar asked Aug 28 '26 15:08

Pratik Patel


1 Answers

The correct syntax to use regex in the assertion would be:

pm.expect(jsonData.error).to.match(/validation error at #\/test\/TC_[0-9]+\/test/)

Each assertion getter need to start with .to and you need to have a valid regex string inside the .match() method.

like image 105
Danny Dainton Avatar answered Aug 30 '26 05:08

Danny Dainton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!