Ballon
Ballon

Reputation: 7204

Jmeter nested regular expression

Is it possible in Jmeter to make nested regular expression?
Or to execute regex on some ${varible}?
And how - if it is possible?

Upvotes: 0

Views: 761

Answers (3)

ant
ant

Reputation: 22948

Yes you can do it by using javascript function. In plain javascript you would use regexp.exec, here is the example link

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp/exec

So using the example from the link above, let's store the cdbBdbsbz in the variable named initialvariable (either by defining initialvariable in user defined variables, extracted from some sampler or however) and then do some regex on this variable this regex -> /d(b+)(d)/ig meaning (from the example link) :

// Match one d followed by one or more b's followed by one d
// Remember matched b's and the following d
// Ignore case

So you can do this in the beanshell sampler by adding :

vars.put("testregex", "${__javaScript(/d(b+)(d)/ig.exec('${initialVariable}')[1],)}");

This is less readable version, you could do it trough java code as well (embedded in the beanshell sampler).

Upvotes: 1

Andrey Pokhilko
Andrey Pokhilko

Reputation: 2668

I use Dummy Sampler for such needs.

Upvotes: 0

BlackGaff
BlackGaff

Reputation: 7707

It is possible, but you need to be sensitive to special characters within the regex, like '$'.

Please see this post: Jmeter - Regex issue with embedded variable and $

And this link for reference: http://www.regular-expressions.info/

Upvotes: 0

Related Questions