You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "Hans C. Poo" <ha...@welinux.cl> on 2011/08/12 23:03:01 UTC

How can i extract from the same link matched two variables

Hi,

I'm matching with a Regex Post Processor an URL. In this URL there is an ID and a NAME, i need to extract both values from the same URL matched.

If i use two consecutive regexes post processors to do the capture, each one capture on a different url from the matched set, making the ID and name to be inconsistent.

How can i extract from the same link matched two variables ?

Thanks
Hans

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How can i extract from the same link matched two variables

Posted by Adrian Speteanu <as...@gmail.com>.
The template I use is $1$$2$$3$ - no other marks and i make sure it
corresponds to the number of "( )" I have in the pattern.

On Tue, Aug 16, 2011 at 4:21 PM, Hans C. Poo <ha...@welinux.cl> wrote:

> Hi,
>
> The answer was the Template format with more than one dollar variable
> $1$-$2$, and then recovering the data with _g1 _g2 and the like.
>
> By the way ¿ the separator in the template is irrelevant ? in my script i
> used $1$-$2$ with dashes, but oliver uses commas.
>
> ¿ The match number must be -1 ?
>
> Thanks
> Hans
>
> ----- Mensaje original -----
> De: "sebb" <se...@gmail.com>
> Para: "JMeter Users List" <jm...@jakarta.apache.org>
> Enviados: Sábado, 13 de Agosto 2011 6:39:17
> Asunto: Re: How can i extract from the same link matched two variables
>
> On 13 August 2011 10:54, Oliver Lloyd <ol...@hotmail.com> wrote:
> > Kudos to Deepak, I'm going to essentially repeat what he just said with
> > examples, to clarify.
> >
> > So, imagine this is my response data:
> > name="name1", value="value1"
> > name="name2", value="value2"
> > name="name3", value="value3"
> >
> > I want one regexp that will give me controlled access to each name and
> value
> > value. So here is my regular expression extractor config:
> > Reference Name: test
> > Regular Expression: name="([^"]+)".*value="([^"]+)"
>
> The .* in the RE above is inefficient, as it includes .* which will
> require back-tracking.
> And if the responses can ever be on the same line, it could skip some
> essential data.
>
> Better would be something that cannot go past the start of the
> 'value=' tag, e.g.
>
> [^v]+
> or perhaps
> \s*,\s*
>
> > Template: $1$,$2$
> > Match No: -1
> > Default: False
> >
> > In my next statement I'm using:
> > test=${test}
> > test_1=${test_1}
> > test_1_g1=${test_1_g1}
> > test_1_g2=${test_1_g2}
> > test_2_g1=${test_2_g1}
> > test_2_g2=${test_2_g2}
> >
> > The result for the above statement is:
> > test=False
> > test_1=name1,value1
> > test_1_g1=name1
> > test_1_g2=value1
> > test_2_g1=name2
> > test_2_g2=value2
> >
> > Some important points:
> > 1. Match No=-1 (that's minus 1) is essential for groups.
> > 2. Template is not required, it only gets used when you do not use the g#
> > suffix, so, with Template blank, ${test_1} will be empty.
> > 3. With Match No=-1, ${test} always = False (default value).
> > 4. In this case, ([^"]+) == (.+?). But ([^"]+) is better, it's more
> > efficient.
> >
> > --
> > View this message in context:
> http://jmeter.512774.n5.nabble.com/How-can-i-extract-from-the-same-link-matched-two-variables-tp4694651p4695839.html
> > Sent from the JMeter - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: How can i extract from the same link matched two variables

Posted by Felix Frank <ff...@mpexnet.de>.
On 08/16/2011 03:21 PM, Hans C. Poo wrote:
> By the way ¿ the separator in the template is irrelevant ? in my script i used $1$-$2$ with dashes, but oliver uses commas.

The template should be of no importance. It describes how the
"ungrouped" result variable is strucured, i.e. the variable without any
_g1 _g2 etc. suffix.

> ¿ The match number must be -1 ?

This is the crucial part, yes (IIRC).

Use a debug sampler to watch how Jmeter spawns variables from you regex
extractor.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How can i extract from the same link matched two variables

Posted by "Hans C. Poo" <ha...@welinux.cl>.
Hi,

The answer was the Template format with more than one dollar variable $1$-$2$, and then recovering the data with _g1 _g2 and the like.

By the way ¿ the separator in the template is irrelevant ? in my script i used $1$-$2$ with dashes, but oliver uses commas.

¿ The match number must be -1 ?

Thanks
Hans

----- Mensaje original -----
De: "sebb" <se...@gmail.com>
Para: "JMeter Users List" <jm...@jakarta.apache.org>
Enviados: Sábado, 13 de Agosto 2011 6:39:17
Asunto: Re: How can i extract from the same link matched two variables

On 13 August 2011 10:54, Oliver Lloyd <ol...@hotmail.com> wrote:
> Kudos to Deepak, I'm going to essentially repeat what he just said with
> examples, to clarify.
>
> So, imagine this is my response data:
> name="name1", value="value1"
> name="name2", value="value2"
> name="name3", value="value3"
>
> I want one regexp that will give me controlled access to each name and value
> value. So here is my regular expression extractor config:
> Reference Name: test
> Regular Expression: name="([^"]+)".*value="([^"]+)"

The .* in the RE above is inefficient, as it includes .* which will
require back-tracking.
And if the responses can ever be on the same line, it could skip some
essential data.

Better would be something that cannot go past the start of the
'value=' tag, e.g.

[^v]+
or perhaps
\s*,\s*

> Template: $1$,$2$
> Match No: -1
> Default: False
>
> In my next statement I'm using:
> test=${test}
> test_1=${test_1}
> test_1_g1=${test_1_g1}
> test_1_g2=${test_1_g2}
> test_2_g1=${test_2_g1}
> test_2_g2=${test_2_g2}
>
> The result for the above statement is:
> test=False
> test_1=name1,value1
> test_1_g1=name1
> test_1_g2=value1
> test_2_g1=name2
> test_2_g2=value2
>
> Some important points:
> 1. Match No=-1 (that's minus 1) is essential for groups.
> 2. Template is not required, it only gets used when you do not use the g#
> suffix, so, with Template blank, ${test_1} will be empty.
> 3. With Match No=-1, ${test} always = False (default value).
> 4. In this case, ([^"]+) == (.+?). But ([^"]+) is better, it's more
> efficient.
>
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/How-can-i-extract-from-the-same-link-matched-two-variables-tp4694651p4695839.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How can i extract from the same link matched two variables

Posted by sebb <se...@gmail.com>.
On 13 August 2011 10:54, Oliver Lloyd <ol...@hotmail.com> wrote:
> Kudos to Deepak, I'm going to essentially repeat what he just said with
> examples, to clarify.
>
> So, imagine this is my response data:
> name="name1", value="value1"
> name="name2", value="value2"
> name="name3", value="value3"
>
> I want one regexp that will give me controlled access to each name and value
> value. So here is my regular expression extractor config:
> Reference Name: test
> Regular Expression: name="([^"]+)".*value="([^"]+)"

The .* in the RE above is inefficient, as it includes .* which will
require back-tracking.
And if the responses can ever be on the same line, it could skip some
essential data.

Better would be something that cannot go past the start of the
'value=' tag, e.g.

[^v]+
or perhaps
\s*,\s*

> Template: $1$,$2$
> Match No: -1
> Default: False
>
> In my next statement I'm using:
> test=${test}
> test_1=${test_1}
> test_1_g1=${test_1_g1}
> test_1_g2=${test_1_g2}
> test_2_g1=${test_2_g1}
> test_2_g2=${test_2_g2}
>
> The result for the above statement is:
> test=False
> test_1=name1,value1
> test_1_g1=name1
> test_1_g2=value1
> test_2_g1=name2
> test_2_g2=value2
>
> Some important points:
> 1. Match No=-1 (that's minus 1) is essential for groups.
> 2. Template is not required, it only gets used when you do not use the g#
> suffix, so, with Template blank, ${test_1} will be empty.
> 3. With Match No=-1, ${test} always = False (default value).
> 4. In this case, ([^"]+) == (.+?). But ([^"]+) is better, it's more
> efficient.
>
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/How-can-i-extract-from-the-same-link-matched-two-variables-tp4694651p4695839.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How can i extract from the same link matched two variables

Posted by Oliver Lloyd <ol...@hotmail.com>.
Kudos to Deepak, I'm going to essentially repeat what he just said with
examples, to clarify.

So, imagine this is my response data:
name="name1", value="value1"
name="name2", value="value2"
name="name3", value="value3"

I want one regexp that will give me controlled access to each name and value
value. So here is my regular expression extractor config:
Reference Name: test
Regular Expression: name="([^"]+)".*value="([^"]+)"
Template: $1$,$2$
Match No: -1
Default: False

In my next statement I'm using:
test=${test}
test_1=${test_1}
test_1_g1=${test_1_g1}
test_1_g2=${test_1_g2}
test_2_g1=${test_2_g1}
test_2_g2=${test_2_g2}

The result for the above statement is:
test=False
test_1=name1,value1
test_1_g1=name1
test_1_g2=value1
test_2_g1=name2
test_2_g2=value2

Some important points:
1. Match No=-1 (that's minus 1) is essential for groups.
2. Template is not required, it only gets used when you do not use the g#
suffix, so, with Template blank, ${test_1} will be empty.
3. With Match No=-1, ${test} always = False (default value).
4. In this case, ([^"]+) == (.+?). But ([^"]+) is better, it's more
efficient.

--
View this message in context: http://jmeter.512774.n5.nabble.com/How-can-i-extract-from-the-same-link-matched-two-variables-tp4694651p4695839.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How can i extract from the same link matched two variables

Posted by Deepak Shetty <sh...@gmail.com>.
>I'm matching with a Regex Post Processor an URL. In this URL there is an ID
and a NAME, i need to extract both values from the same URL matched.
Possible using regex groups
say your regex is like id=(someconditionthatmatchesid)
name=(someconditionthatmatchesname) => The round brackets are important here
In template say you have $1$~$2$ then the matching value will look like
id~name when you say ${variableName_index}

If you want just the ID you use ${variableName_INDEX_g1} and for name you
use ${variableName_INDEX_g2} where Index is the match number(Assuming you
have multiple results). if you just have a single result the
${variableName_g1} and ${variableName_g2}. g1 corresponds to the first
matching group which in the example above is the id.

regards
deepak


On Fri, Aug 12, 2011 at 2:03 PM, Hans C. Poo <ha...@welinux.cl> wrote:

> Hi,
>
> I'm matching with a Regex Post Processor an URL. In this URL there is an ID
> and a NAME, i need to extract both values from the same URL matched.
>
> If i use two consecutive regexes post processors to do the capture, each
> one capture on a different url from the matched set, making the ID and name
> to be inconsistent.
>
> How can i extract from the same link matched two variables ?
>
> Thanks
> Hans
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>