You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Eda Srinivasareddy <ed...@yahoo.com> on 2003/12/17 06:00:09 UTC

Regular Expressions - Doubts

Hi all

 

Following are some of the doubts that we got while using for testing one of our applications?

 

1. Is there any way to find out the last Match number of the template of a regular expression instead of finding randomly by using 0 or by using some number say N to find the Nth Match Number?

 

2. Regular expression was not working proper in the case of the following code of a multi selection list box. The code is 

 

<select>

<option value="abc">&lt;abc</option><option value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>

 

The regular expression details I used:

                                      Regular expression: \<option value=\"(.*)\"\>

                                      Template:                 $1$

                                      Match No:                 1

Answer expected:   abc

Answer received: abc">&lt;abc</option><option value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>

 

My doubt here is, did I do any mistake? If there is no mistake, why it is not giving only abc?

 

Thanks

Eda



---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Re: Regular Expressions - Doubts

Posted by Prakash M V <pr...@granada-learning.com>.
Hi

I think the problem in ur expression is that u are trying to match all the
values by saying it as .*), try to match for the value which u want to
retrieve and then finishing it by speech mark, Like in ur expression u have
given as Regular expression: \<option value=\"(.*)\"\> instead try with

Regular expression: \<option value=\"(.*)\"">&lt\> something like this, iam
not sure , just thought to give u an idea. by specifying the speech mark
>&lt it makes the expression match to retrieve the value untill &lt

regards

----- Original Message ----- 
From: "Eda Srinivasareddy" <ed...@yahoo.com>
To: "JMeter User List" <jm...@jakarta.apache.org>
Sent: Wednesday, December 17, 2003 5:00 AM
Subject: Regular Expressions - Doubts


>
> Hi all
>
>
>
> Following are some of the doubts that we got while using for testing one
of our applications?
>
>
>
> 1. Is there any way to find out the last Match number of the template of a
regular expression instead of finding randomly by using 0 or by using some
number say N to find the Nth Match Number?
>
>
>
> 2. Regular expression was not working proper in the case of the following
code of a multi selection list box. The code is
>
>
>
> <select>
>
> <option value="abc">&lt;abc</option><option
value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>
>
>
>
> The regular expression details I used:
>
>                                       Regular expression: \<option
value=\"(.*)\"\>
>
>                                       Template:                 $1$
>
>                                       Match No:                 1
>
> Answer expected:   abc
>
> Answer received: abc">&lt;abc</option><option
value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>
>
>
>
> My doubt here is, did I do any mistake? If there is no mistake, why it is
not giving only abc?
>
>
>
> Thanks
>
> Eda
>
>
>
> ---------------------------------
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing


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


Re: Regular Expressions - Doubts

Posted by Jordi Salvat i Alabart <js...@atg.com>.
I've read comments saying this one is excellent:

http://www.oreilly.com/catalog/regex/

En/na Eda Srinivasareddy ha escrit:
> Hi Salvat and Prakash
>  
> Thank you very much for your responses. From your responses I came to know that I have to know more about Regular Expressions before really trying them.
>  
> Please suggest me a good book for Regular expressions.
>  
> Thanks a lot
> Eda
> 
> Jordi Salvat i Alabart <js...@atg.com> wrote:
> 
> 
> En/na Eda Srinivasareddy ha escrit:
> 
>>Hi all
>>
>>
>>
>>Following are some of the doubts that we got while using for testing one of our applications?
>>
>>
>>
>>1. Is there any way to find out the last Match number of the template of a regular expression instead of finding randomly by using 0 or by using some number say N to find the Nth Match Number?
>>
> 
> 
> I don't think there is. Actually, I'm pretty sure there isn't.
> 
> But probably you can devise a regexp that only matches on the correct 
> entry. Keep reading.
> 
> 
>>2. Regular expression was not working proper in the case of the following code of a multi selection list box. The code is 
>>
>>
>>
>>
>>>><abc<abc<abc
>>
>>
>>
>>The regular expression details I used:
>>
>>Regular expression: \
>>
>>Template: $1$
>>
>>Match No: 1
>>
>>Answer expected: abc
>>
>>Answer received: abc"><abc<abc<abc
>>
> 
> 
> It is working correctly. "*" is a "greedy" operator: it will match as 
> much as you can. Your regexp says: find me something starting with 
> and grab what's inbetween -- and 
> that's what it's doing, only that it is the FIRST "> in your text.
> 
> You may use "*?" instead: it's a "reluctant" operator. But it performs 
> really poorly if there's no match or if the match is very long.
> 
> Even beter:
> 
> ]*)\">
> 
> And talking about greedy/reluctant operators, you can use this to match 
> the last such option:
> 
> .*]*)\">
> 
> Because .* is greedy, it will match everything it can -- and leave only 
> the last 
> Makes sense?
> 
> 
>>My doubt here is, did I do any mistake? If there is no mistake, why it is not giving only abc?
>>
>>
>>
>>Thanks
>>
>>Eda
>>
>>
>>
>>---------------------------------
>>Do you Yahoo!?
>>New Yahoo! Photos - easier uploading and sharing
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> ---------------------------------
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing


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


Re: Regular Expressions - Doubts

Posted by Eda Srinivasareddy <ed...@yahoo.com>.
Hi Salvat and Prakash
 
Thank you very much for your responses. From your responses I came to know that I have to know more about Regular Expressions before really trying them.
 
Please suggest me a good book for Regular expressions.
 
Thanks a lot
Eda

Jordi Salvat i Alabart <js...@atg.com> wrote:


En/na Eda Srinivasareddy ha escrit:
> Hi all
> 
> 
> 
> Following are some of the doubts that we got while using for testing one of our applications?
> 
> 
> 
> 1. Is there any way to find out the last Match number of the template of a regular expression instead of finding randomly by using 0 or by using some number say N to find the Nth Match Number?
> 

I don't think there is. Actually, I'm pretty sure there isn't.

But probably you can devise a regexp that only matches on the correct 
entry. Keep reading.

> 
> 2. Regular expression was not working proper in the case of the following code of a multi selection list box. The code is 
> 
> 
> 
> > > <abc<abc<abc
> 
> 
> 
> The regular expression details I used:
> 
> Regular expression: \
> 
> Template: $1$
> 
> Match No: 1
> 
> Answer expected: abc
> 
> Answer received: abc"><abc<abc<abc
> 

It is working correctly. "*" is a "greedy" operator: it will match as 
much as you can. Your regexp says: find me something starting with 
and grab what's inbetween -- and 
that's what it's doing, only that it is the FIRST "> in your text.

You may use "*?" instead: it's a "reluctant" operator. But it performs 
really poorly if there's no match or if the match is very long.

Even beter:

]*)\">

And talking about greedy/reluctant operators, you can use this to match 
the last such option:

.*]*)\">

Because .* is greedy, it will match everything it can -- and leave only 
the last 
Makes sense?

> 
> My doubt here is, did I do any mistake? If there is no mistake, why it is not giving only abc?
> 
> 
> 
> Thanks
> 
> Eda
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing


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


---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Re: Regular Expressions - Doubts

Posted by Jordi Salvat i Alabart <js...@atg.com>.

En/na Eda Srinivasareddy ha escrit:
> Hi all
> 
>  
> 
> Following are some of the doubts that we got while using for testing one of our applications?
> 
>  
> 
> 1. Is there any way to find out the last Match number of the template of a regular expression instead of finding randomly by using 0 or by using some number say N to find the Nth Match Number?
> 

I don't think there is. Actually, I'm pretty sure there isn't.

But probably you can devise a regexp that only matches on the correct 
entry. Keep reading.

> 
> 2. Regular expression was not working proper in the case of the following code of a multi selection list box. The code is 
> 
>  
> 
> <select>
> 
> <option value="abc">&lt;abc</option><option value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>
> 
>  
> 
> The regular expression details I used:
> 
>                                       Regular expression: \<option value=\"(.*)\"\>
> 
>                                       Template:                 $1$
> 
>                                       Match No:                 1
> 
> Answer expected:   abc
> 
> Answer received: abc">&lt;abc</option><option value="abc">&lt;abc</option><option value="abc">&lt;abc</option></select>
> 

It is working correctly. "*" is a "greedy" operator: it will match as 
much as you can. Your regexp says: find me something starting with 
<option value=" and ending with "> and grab what's inbetween -- and 
that's what it's doing, only that it is the FIRST <option and the LAST 
"> in your text.

You may use "*?" instead: it's a "reluctant" operator. But it performs 
really poorly if there's no match or if the match is very long.

Even beter:

<option value=\"([^">]*)\">

And talking about greedy/reluctant operators, you can use this to match 
the last such option:

.*<option value=\"([^">]*)\">

Because .* is greedy, it will match everything it can -- and leave only 
the last <option for the rest of the expression.

Makes sense?

> 
> My doubt here is, did I do any mistake? If there is no mistake, why it is not giving only abc?
> 
>  
> 
> Thanks
> 
> Eda
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing


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