user1844124
user1844124

Reputation: 23

Jmeter Regular Expression issue with excluding patterns

I need a regex to find the last match of a pattern in JMETER This is the string I have

"blah blah n="12" blah blah n="13" blah blah n="14" KEYWORD blah blah"

what I want is the last n=value before the keyword

This is the regex I tried,

n="(.(?!n=).)"KEYWORD

but the regex matches everything between first n= and KEYWORD. It doesn't exclude the n= patterns in between

Can somebody help me crack this nut??

Upvotes: 2

Views: 1347

Answers (1)

stema
stema

Reputation: 93026

Why do you need the negative lookahead, when there is the KEYWORD following? Then you could just use

n="(\d+)"\s*KEYWORD

and find your value in "$1". See it here on Regexer.

If the KEYWORD can change you can ensure with a negative lookahead that there is no more "n=" following in the row

n="(\d+)(?!.*n=)

See it on Regexr

and if you don't want the "n="" to be part of the match, you put that in a look behind assertion:

(?<=n=")\d+(?!.*n=)

See it on Regexr

Upvotes: 2

Related Questions