简体   繁体   中英

Gatling - Scala extract substring

I have extracted a string from the HTML response body using the below REGEX code

.check(regex("pzTransactionId=.*pzFromFrame").find.saveAs("pzTransId"))

Extracted value is pzTransactionId=1g2h3j1h2g35k6j4lnx93jsn83jsn1e&pzFromFrame

But I need a substring from the extracted value which is g2h3j1h2g35k6j4lnx93jsn83jsn1e . How do I do that? I need this value so that I can pass it in subsequent request. I tried the below options but it did not work.

.exec{session
val pztransactionid = (session("pzTransId").as[String].substring(0,5))}

But if I print pztransactionid it says value is not available in the session.

Your regex is wrong, it should be:

.check(regex(".*pzTransactionId=(.*)&pzFromFrame.*").find.saveAs("pzTransId"))

I recommend you read Java regex documentation, in particular capture groups.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM