How to make regular expression unique for multiple values

How to make regular expression unique for multiple values



My response having same values at 2 places like


http://images.123456_120*75
http://images.123456_120*75
http://images.784217_120*75
http://images.784217_120*75



In this I need to capture 123456 & 784217 only one time.



I was using regex as http://images.(.+?)_120*75 which extracting all 4 values .But my concern is I need one value among 2 for each. Can u pls help me
thanks in advance ?


http://images.(.+?)_120*75




4 Answers
4



One way, is to have 2 post processor with the same regex. Now, in the 1st regular extractor use Match No: value as 1 and in 2nd use Match No: value as 4.



enter image description here



Hope this helps.





But if the index number of each value isn't known?
– user7294900
Aug 28 at 13:35





it is ok but we need to pass each variable once as u shown in the image. but not only 2 values are in my response there are a lot actually I want to make them unique and want to pass at once
– biyyapu
Aug 29 at 5:02



Doing it using regular expressions is quite tricky, I would recommend going for JSR223 PostProcessor and Groovy language instead.



Put the following code into "Script" area


(prev.getResponseDataAsString() =~ "http://images.(\d+)_120\*75").findAll().unique().eachWithIndex match, idx ->
vars.put('image_' + idx,match.get(1))



If everything goes well you should see the following JMeter Variables generated:


image_0=123456
image_1=784217
etc.





thnku Dmitri i'll try this and let u know.
– biyyapu
Aug 30 at 6:48





it is giving regex.patternsyntaxexception: illegeal/unsupported escape sequence near index 75
– biyyapu
Aug 30 at 7:22



This should work, it captures unique values only once:


(d+)(?:_)(?![sS]*1)



Try Demo here



Explanation



(d+)(?:_)(?![sS]*1)


(d+)(?:_)(?![sS]*1)



1st Capturing Group (d+)


(d+)



d+ matches a digit (equal to [0-9])


d+


[0-9]



Non-capturing group (?:_)


(?:_)



_ matches the character _ literally (case sensitive)


_


_



Negative Lookahead (?![sS]*1)


(?![sS]*1)



Assert that the Regex below does not match
Match a single character present in the list below [sS]*


[sS]*



s matches any whitespace character (equal to [rntfv ])


s


[rntfv ]



S matches any non-whitespace character (equal to [^rntfv ])


S


[^rntfv ]



1 matches the same text as most recently matched by the 1st capturing group


1





The ids to capture are dynamic
– user7294900
Aug 28 at 15:06





@user7294900 but your question reads like that. do you know their range?
– The Scientific Method
Aug 28 at 15:12






the above expression is ok but I don know the values which should come in the response and there are no only 2 values there are a lot of multiple repeted one I wan to make all unique
– biyyapu
Aug 29 at 5:00





@biyyapu you can try it now, it is capturing multiple unique values.
– The Scientific Method
Aug 29 at 5:56





@biyyapu I'm not the OP, biyyapu should say if it work
– user7294900
Aug 29 at 13:20



Perhaps you could capture the whole match in a group and capture the digits in a second group. Then use a negative lookahead to assert that what is captured in group 1 does not occur anymore giving you the unique values.



The digits you want to match are in capturing group 2. Note that to match the dot . and the asterix * literally you have to escape them.


.


*



(http://images.(d+)_120*75)(?![sS]*1)


(http://images.(d+)_120*75)(?![sS]*1)



Regex demo



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)