You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by dino7777 <pa...@gmail.com> on 2011/10/18 13:28:23 UTC
beanshell get highest value of a regular expression
Hi,
I read out "id" values from a list with regEx, reference name "IDH".
Now I know, that ${"IDH_matchNr) gives the total number of groups.
I want to extract the highest "id" value for further use.
I tried following beanshell, but no luck:
*count = vars.get("IDH_matchNr");
new = 1;
for (i=0; i < count; i++) {
lower = vars.get("IDH_g",i); // I guess this one does not give me
the current value for the loop
if (lower > new) {
new = lower;
}
}
vars.put("IDH",new);
*
thanks in advance
--
View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4913331.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: beanshell get highest value of a regular expression
Posted by sebb <se...@gmail.com>.
On 18 October 2011 12:28, dino7777 <pa...@gmail.com> wrote:
> Hi,
>
> I read out "id" values from a list with regEx, reference name "IDH".
> Now I know, that ${"IDH_matchNr) gives the total number of groups.
>
> I want to extract the highest "id" value for further use.
>
> I tried following beanshell, but no luck:
>
> *count = vars.get("IDH_matchNr");
> new = 1;
> for (i=0; i < count; i++) {
OK.
> lower = vars.get("IDH_g",i); // I guess this one does not give me
No, because:
- vars.get() only supports a single parameter - the name of the variable
- anyway, the variable is not called IDH_gn.
The variable names are all documented here:
http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Regular_Expression_Extractor_parms
(scroll to the end of the table)
> the current value for the loop
> if (lower > new) {
> new = lower;
> }
> }
> vars.put("IDH",new);
> *
>
> thanks in advance
>
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4913331.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: beanshell get highest value of a regular expression
Posted by ZK <st...@gmail.com>.
Hi,
I couldn't test this when I replied as I didn't have access to jmeter, but
Sebb is correct :)
The 'g' part of the variable is not required
I tested this and it seems to work for me now!
/Regex Match No = -1/
/totalMatches = Integer.decode(vars.get("defaultPrice_matchNr"));
int arrSize = totalMatches;
int[] myArray = new int[arrSize];
for (int i = 0; i < myArray.length; i++)
{
myArray[i]=Integer.decode(vars.get("*defaultPrice_*"+(i+1)));
}
Arrays.sort(myArray);
System.out.println("Minimum = " + myArray[0]);
System.out.println("Maximum = " + myArray[myArray.length-1]); /
ZK
--
View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4916720.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: beanshell get highest value of a regular expression
Posted by sebb <se...@gmail.com>.
On 19 October 2011 00:21, David Luu <ma...@gmail.com> wrote:
> For referencing the var when getting it, couldn't we just do string
> concatenation? like vars.get("IDH_g" + i)
Yes, but again that is the wrong name for Match No = -1
> On Tue, Oct 18, 2011 at 9:39 AM, sebb <se...@gmail.com> wrote:
>
>> On 18 October 2011 17:35, Deepak Shetty <sh...@gmail.com> wrote:
>> > hi
>> > I think what sebb is saying is that you should be looking at IDH_1 (and
>> not
>> > IDH_g1 - but these might be the same depending on the regex :) )
>>
>> The variables that are set depend on the Regex Extractor settings, as
>> described under
>>
>>
>> http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Regular_Expression_Extractor_parms
>>
>> In particular, note that the variables depend on the setting of "Match
>> No.".
>>
>> > regards
>> > deepak
>> >
>> > On Tue, Oct 18, 2011 at 9:31 AM, ZK <st...@gmail.com> wrote:
>> >
>> >> Sebb I see what you are saying regarding a single match, however; would
>> >> this
>> >> work if the regEx extractor Match No was set to -1
>> >>
>> >> ?
>> >>
>> >>
>> >> ZK
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4914413.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: beanshell get highest value of a regular expression
Posted by David Luu <ma...@gmail.com>.
For referencing the var when getting it, couldn't we just do string
concatenation? like vars.get("IDH_g" + i)
On Tue, Oct 18, 2011 at 9:39 AM, sebb <se...@gmail.com> wrote:
> On 18 October 2011 17:35, Deepak Shetty <sh...@gmail.com> wrote:
> > hi
> > I think what sebb is saying is that you should be looking at IDH_1 (and
> not
> > IDH_g1 - but these might be the same depending on the regex :) )
>
> The variables that are set depend on the Regex Extractor settings, as
> described under
>
>
> http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Regular_Expression_Extractor_parms
>
> In particular, note that the variables depend on the setting of "Match
> No.".
>
> > regards
> > deepak
> >
> > On Tue, Oct 18, 2011 at 9:31 AM, ZK <st...@gmail.com> wrote:
> >
> >> Sebb I see what you are saying regarding a single match, however; would
> >> this
> >> work if the regEx extractor Match No was set to -1
> >>
> >> ?
> >>
> >>
> >> ZK
> >>
> >> --
> >> View this message in context:
> >>
> http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4914413.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: beanshell get highest value of a regular expression
Posted by sebb <se...@gmail.com>.
On 18 October 2011 17:35, Deepak Shetty <sh...@gmail.com> wrote:
> hi
> I think what sebb is saying is that you should be looking at IDH_1 (and not
> IDH_g1 - but these might be the same depending on the regex :) )
The variables that are set depend on the Regex Extractor settings, as
described under
http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Regular_Expression_Extractor_parms
In particular, note that the variables depend on the setting of "Match No.".
> regards
> deepak
>
> On Tue, Oct 18, 2011 at 9:31 AM, ZK <st...@gmail.com> wrote:
>
>> Sebb I see what you are saying regarding a single match, however; would
>> this
>> work if the regEx extractor Match No was set to -1
>>
>> ?
>>
>>
>> ZK
>>
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4914413.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: beanshell get highest value of a regular expression
Posted by Deepak Shetty <sh...@gmail.com>.
hi
I think what sebb is saying is that you should be looking at IDH_1 (and not
IDH_g1 - but these might be the same depending on the regex :) )
regards
deepak
On Tue, Oct 18, 2011 at 9:31 AM, ZK <st...@gmail.com> wrote:
> Sebb I see what you are saying regarding a single match, however; would
> this
> work if the regEx extractor Match No was set to -1
>
> ?
>
>
> ZK
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4914413.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: beanshell get highest value of a regular expression
Posted by ZK <st...@gmail.com>.
Sebb I see what you are saying regarding a single match, however; would this
work if the regEx extractor Match No was set to -1
?
ZK
--
View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4914413.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: beanshell get highest value of a regular expression
Posted by sebb <se...@gmail.com>.
On 18 October 2011 15:51, ZK <st...@gmail.com> wrote:
> hi,
> you could try this:
>
> totalMatches = Integer.decode(vars.get("IDH_matchNr"));
> int arrSize = totalMatches;
> int[] myArray = new int[arrSize];
>
>
> for (int i = 0; i < myArray.length; i++)
> {
> myArray[i]=Integer.decode(vars.get("IDH_g"+(i+1)));
> }
>
> Arrays.sort(myArray);
> System.out.println("Minimum = " + myArray[0]);
> System.out.println("Maximum = " + myArray[myArray.length-1]);
>
>
> /(disclaimer.... I am a tester not a programmer)/
Syntax looks OK, but the generated variable name looks wrong; IDH_g1,
IDH_g2 etc. are the groups returned for a single match.
If the original poster adds a Debug Sampler after the Regex Extractor,
it will be obvious what the variable names are.
>
> ZK
>
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4913980.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: beanshell get highest value of a regular expression
Posted by ZK <st...@gmail.com>.
hi,
you could try this:
totalMatches = Integer.decode(vars.get("IDH_matchNr"));
int arrSize = totalMatches;
int[] myArray = new int[arrSize];
for (int i = 0; i < myArray.length; i++)
{
myArray[i]=Integer.decode(vars.get("IDH_g"+(i+1)));
}
Arrays.sort(myArray);
System.out.println("Minimum = " + myArray[0]);
System.out.println("Maximum = " + myArray[myArray.length-1]);
/(disclaimer.... I am a tester not a programmer)/
ZK
--
View this message in context: http://jmeter.512774.n5.nabble.com/beanshell-get-highest-value-of-a-regular-expression-tp4913331p4913980.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