sree raja
sree raja

Reputation: 177

How to get sub-string in jmeter

My response of an API is like "details" : "AccNo : 102478955441205" When i used "Regular Expression Extractor" to store the value in a variable it is successfully stored with the following regex "details"\s:\s*"([^"]*)" The problem is when I'm trying to use it, the response is coming as AccNo : 1010201213000005 but what i need is just the number. Can someone help me out

Json Body

{ "statusCode" : "sfewr", "statusDes" : "Record inserted successfully!! ", "statusType" : "X", "details" : "AccNo : 102478955441205" }

Regex used :

"details"\s:\s*"([^"]*)"

Actual Result

"AccNo : 102478955441205"

Expected Result:

102478955441205

Upvotes: 0

Views: 50

Answers (1)

Pushpesh Kumar Rajwanshi
Pushpesh Kumar Rajwanshi

Reputation: 18357

You need to modify your regex a bit, so your group1 only matches the digits. You can use this regex,

"details"\s:\s*"\D*(\d+)"

I've used \D* to match any non-digit text and have kept it out of first grouping pattern so your group1 contents are only digits. Also changed [^"]* to \d+ as what you want to get in group1 is only digits. Although, if you want, you can retain [^"]* too instead of \d+

Demo

Upvotes: 1

Related Questions