You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Gavin Maselino <ga...@hotmail.com> on 2013/11/13 18:11:23 UTC

Jmeter Regex advice - qualifier string after regex

Hi
So here is an example of the JMeter response I am struggling with:
<div><a href=12354><span>Foo1<a href=12357><span>Foo2</div>
The text I need to use regex on is the ahref next to Foo2 (12357).When I do this regex on RegexTester.com (a href=(.*)><span>Foo2), it returns the href value for Foo1.
Can anyone advise how I can get the ahref for Foo2?
 I cannot use XPath extraction as the real response I am using has hexademical in it so a '<' is actually encoded as '\u003C'.  
Thanks 
 		 	   		  

Re: Jmeter Regex advice - qualifier string after regex

Posted by Gavin Maselino <ga...@hotmail.com>.
Thanks also Deepak for your help. 

> On 13 Nov 2013, at 19:01, "Deepak Shetty" <sh...@gmail.com> wrote:
> 
> Hi
> I guess your expression is too greedy (Im assuming you are getting a lot
> more than 12354
> 
> a href=([^>]*)><span>Foo2
> Note that your snippet is invalid html and people tend to put in quotes or
> apostrophes or add spaces or more attributes and if you want to write an
> expression that doesnt break easily youll have to change the regex.
> the other way would be to modify your expression to have .*? - that would
> work but it would be inefficient
> 
> 
> On Wed, Nov 13, 2013 at 9:11 AM, Gavin Maselino
> <ga...@hotmail.com>wrote:
> 
>> Hi
>> So here is an example of the JMeter response I am struggling with:
>> <div><a href=12354><span>Foo1<a href=12357><span>Foo2</div>
>> The text I need to use regex on is the ahref next to Foo2 (12357).When I
>> do this regex on RegexTester.com (a href=(.*)><span>Foo2), it returns the
>> href value for Foo1.
>> Can anyone advise how I can get the ahref for Foo2?
>> I cannot use XPath extraction as the real response I am using has
>> hexademical in it so a '<' is actually encoded as '\u003C'.
>> Thanks
>> 

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


Re: Jmeter Regex advice - qualifier string after regex

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
I guess your expression is too greedy (Im assuming you are getting a lot
more than 12354

a href=([^>]*)><span>Foo2
Note that your snippet is invalid html and people tend to put in quotes or
apostrophes or add spaces or more attributes and if you want to write an
expression that doesnt break easily youll have to change the regex.
the other way would be to modify your expression to have .*? - that would
work but it would be inefficient


On Wed, Nov 13, 2013 at 9:11 AM, Gavin Maselino
<ga...@hotmail.com>wrote:

> Hi
> So here is an example of the JMeter response I am struggling with:
> <div><a href=12354><span>Foo1<a href=12357><span>Foo2</div>
> The text I need to use regex on is the ahref next to Foo2 (12357).When I
> do this regex on RegexTester.com (a href=(.*)><span>Foo2), it returns the
> href value for Foo1.
> Can anyone advise how I can get the ahref for Foo2?
>  I cannot use XPath extraction as the real response I am using has
> hexademical in it so a '<' is actually encoded as '\u003C'.
> Thanks
>

Re: Jmeter Regex advice - qualifier string after regex

Posted by Gavin Maselino <ga...@hotmail.com>.
Hi Robin. Your first solution works perfectly, and also thanks for the tip on non greedy matching research. 



> On 13 Nov 2013, at 19:26, "Robin D. Wilson" <rw...@gmail.com> wrote:
> 
> Try this:
> 
> a href=([^>]*)><span>Foo2
> 
> That tells Regex to get everything in the () that doesn't include a '>' character...
> 
> Your other regex is actually getting this string:
> 
> 12354><span>Foo1<a href=12357
> 
> That's because by nature, the 'regex' is 'greedy' in its match. So it is matching all characters after the first 'href=', and up to
> the '><span>Foo2' string.
> 
> Try googling "regex non greedy match", you will find multiple ways to handle this.
> 
> --
> Robin D. Wilson
> Sr. Director of Web Development
> KingsIsle Entertainment, Inc.
> VOICE: 512-777-1861
> http://www.kingsisle.com
> 
> 
> -----Original Message-----
> From: Gavin Maselino [mailto:gavinmaselino@hotmail.com] 
> Sent: Wednesday, November 13, 2013 11:11 AM
> To: user@jmeter.apache.org
> Subject: Jmeter Regex advice - qualifier string after regex
> 
> Hi
> So here is an example of the JMeter response I am struggling with:
> <div><a href=12354><span>Foo1<a href=12357><span>Foo2</div>
> The text I need to use regex on is the ahref next to Foo2 (12357).When I do this regex on RegexTester.com (a href=(.*)><span>Foo2),
> it returns the href value for Foo1.
> Can anyone advise how I can get the ahref for Foo2?
> I cannot use XPath extraction as the real response I am using has hexademical in it so a '<' is actually encoded as '\u003C'.  
> Thanks 
>                         
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
> 

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


RE: Jmeter Regex advice - qualifier string after regex

Posted by "Robin D. Wilson" <rw...@gmail.com>.
Try this:

a href=([^>]*)><span>Foo2

That tells Regex to get everything in the () that doesn't include a '>' character...

Your other regex is actually getting this string:

12354><span>Foo1<a href=12357

That's because by nature, the 'regex' is 'greedy' in its match. So it is matching all characters after the first 'href=', and up to
the '><span>Foo2' string.

Try googling "regex non greedy match", you will find multiple ways to handle this.

--
Robin D. Wilson
Sr. Director of Web Development
KingsIsle Entertainment, Inc.
VOICE: 512-777-1861
http://www.kingsisle.com


-----Original Message-----
From: Gavin Maselino [mailto:gavinmaselino@hotmail.com] 
Sent: Wednesday, November 13, 2013 11:11 AM
To: user@jmeter.apache.org
Subject: Jmeter Regex advice - qualifier string after regex

Hi
So here is an example of the JMeter response I am struggling with:
<div><a href=12354><span>Foo1<a href=12357><span>Foo2</div>
The text I need to use regex on is the ahref next to Foo2 (12357).When I do this regex on RegexTester.com (a href=(.*)><span>Foo2),
it returns the href value for Foo1.
Can anyone advise how I can get the ahref for Foo2?
 I cannot use XPath extraction as the real response I am using has hexademical in it so a '<' is actually encoded as '\u003C'.  
Thanks 
 		 	   		  


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