3

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 ?

katmanco
  • 1,146
  • 12
  • 24
biyyapu
  • 77
  • 10

4 Answers4

0

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.

sunny_teo
  • 1,961
  • 1
  • 7
  • 11
  • But if the index number of each value isn't known? – Ori Marko Aug 28 '18 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 '18 at 05:02
0

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

  1. Add JSR223 PostProcessor as a child of the request which returns above images URLs
  2. 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))
    }
    
  3. If everything goes well you should see the following JMeter Variables generated:

    image_0=123456
    image_1=784217
    etc.
    
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

This should work, it captures unique values only once:

(\d+)(?:_)(?![\s\S]*\1)

Try Demo here

Explanation

(\d+)(?:_)(?![\s\S]*\1)

1st Capturing Group (\d+)

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

  • Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

Non-capturing group (?:_)

_ matches the character _ literally (case sensitive)

Negative Lookahead (?![\s\S]*\1)

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

  • Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)

\s matches any whitespace character (equal to [\r\n\t\f\v ])

\S matches any non-whitespace character (equal to [^\r\n\t\f\v ])

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

The Scientific Method
  • 2,374
  • 2
  • 14
  • 25
0

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)(?![\s\S]*\1)

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70