Posted on 6 December 2013

Do you have a correlation which you can’t solve because the values of the left and right boundary are dynamic? Correlation is an essential part of performance test scripting and there are plenty of different challenges with correlation. Imagine having a value of “GraphA123567EndGraphA” and the goal is to correlate 123567

From the example above, the left and right boundaries would be “LB=GraphA” “RB=EndGraphA”
What if the word GraphA is dynamic and can be anything from GraphA-GraphZ?

There is a solution at hand!

Using web_reg_save_param_regex will allow the user to grab a correlation value using dynamic left and right boundaries. This function uses the power of regular expressions, below are a few examples:

Example 1:
Source: “GraphA123567EndGraphA”
Solution: web_reg_save_param_regexp(“ParamName=CorrValue”, “RegExp=\“Graph[A-Za-z]\”, \“([0-9]+)\”, \“EndGraph[A-Za-z]\””, LAST);
Result: 123567

Example 2:
Correlate the values from a drop down list of a form
Source: dropdown >>> red, blue, green
Solution: web_reg_save_param_regexp(“ParamName=ColourList”, “RegExp=option=[0-9]+>([A-Za-z])

• {ColourList1}=red
• {ColourList2}=blue
• {ColourList3}=green

Example 3:
Correlate up till the end of 642
Source: J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642″];
Solution: web_reg_save_param_regexp(“ParamName=SecurityString”,”RegExp=\”([A-Z0-9a-z\\\\+]+==\\|[0-9]+)\”\\];”,LAST);
Result:J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642

Example 4:
Correlate only “634998513832503642” Source:

`J\u002blsGd3zj1qdP\u002bvk0vDRaKyJFde5tCa6spDEy08SNab1hP8j5GTs4j6\u002f\u002bTqOwvxMHEQZLWd\u002btu8NlHJrVAarIQ==|634998513832503642"];`

Solution:

```web_reg_save_param_regexp("ParamName=SecurityString",
"RegExp=\"[A-Z0-9a-z\\\\+]+==\\|([0-9]+)\"\\];",
LAST);
```

Result: 634998513832503642

So what is a Regular Expression?
Also known as regex, a regular expression is a search string which enables matching of a string. Think of it as an advance searching function which can pick out values from a string of multiple characters.

Examples of regex:

• \d matches a single digit
• \w matches a single word (including alphanumeric characters and underscore)
• [A-Z]+ matches any word which is upper case
• [a-z]+ matches any word which is lower case
• [0-9]+ matches any numeric value

There are other alternatives to web_reg_save_param_regexp. However these functions are limited and not as flexible.

LB/DIG RB/DIG – # will be a wildcard for a numeric value“session_id_##”

• Adding LB/IC/DIG will ignore case
• “LB/IC/DIG=session_id_##=” (e.g. Session_id_20)

LB/ALNUM or RB/ALNUM – ^ will be a wildcard for an alphanumeric value

• ALNUMIC – ignore case
• ALNUMLC – match only lower case
• ALNUMUC – match only upper case

SaveOffSet

• If there is a dynamic value for a boundary e.g. “session_id_2” (3,4,5)
• SaveOffSet = 2 (to cover “2=”)
• Web_reg_save_param(“SessionID”, “LB=session_id_”, “RB=\””, “SaveOffSet=2”, LAST);

LR implementation

• PERL based
• LR 11 does not support multiple capture groups however this is now supported in LR 11.52 (example below)

Example Multiple Capture Groups
Source: rows”:[[“NW,RO,RA”,”DLY”,”10/07/2011″,”10/17/2011″,”10/01/2011″,”RA”,”Y”,”FR”,”AMEA”,”AC”,”1945″,”50″,”50″,”AC 100IOSH-08″,”UserDefined”,”10/07/2011″,”Reassigned”…”

Solution: web_reg_save_param_regexp(“ParamName=ParamValue”,”RegExp=rows”:\[\[“[^”\r\n]*”,”([A-Z]{3})”,”[^”\r\n]*”,”[^”\r\n]*”,”[^\/]+\/[\d]+?\/2011″,”[A-Za-z]*”,”[^”\r\n]*”,”[^”\r\n]*”,”([^”\r\n]*)”,”[^”\r\n]*”,”([^”\r\n]*)”,LAST);

Result:

• {ParamValue1} = DLY
• {ParamValue2} = AMEA
• {ParamValue3} = 1945

(input type=”hidden” name=”.*?3b0a0a4a1a1a\db3-h)

Could you please help me in representing the above regex (valid when tried from reg ex tools) in loadrunner. I tried the below but does not match. I just need the count of the matches. Please note.\d is a unique digit in the expression and need to be

web_reg_save_param_regexp(
“ParamName=Correlation3”,
“RegExp=(input type=\”hidden” name=.*?3b0a0a4a1a1a\db3-h) ”
“Ordinal=All”,
// “NotFound=Warning”,
SEARCH_FILTERS,
“Scope=Body”,
LAST );

Lionel

Hi,

Can you escape the \d with \\d

You also should revisit the capture group because at the moment you are capturing everything from the word “input” till the last character of the name value

Leo

I followed the blog and created a regular expression with multiple capturing groups.However I cant use the variables the way you showed.(ie {Param1} {Param2} etc)

govardhan

Hi Expert,
In Example Multiple Capture Groups :
Source: rows”:[[“NW,RO,RA”,”DLY”,”10/07/2011″,”10/17/2011″,”10/01/2011″,”RA”,”Y”,”FR”,”AMEA”,”AC”,”1945″,”50″,”50″,”AC 100IOSH-08″,”UserDefined”,”10/07/2011″,”Reassigned”…”
and Regularexperssion you wrote as below
Solution: web_reg_save_param_regexp(“ParamName=ParamValue”,”RegExp=rows”:\[\[“[^”\r\n]*”,”([A-Z]{3})”,”[^”\r\n]*”,”[^”\r\n]*”,”[^\/]+\/[\d]+?\/2011″,”[A-Za-z]*”,”[^”\r\n]*”,”[^”\r\n]*”,”([^”\r\n]*)”,”[^”\r\n]*”,”([^”\r\n]*)”,LAST);

__ I have few questions __
1. you had used \r\n in above regexp, but is for new lines . as per the source code in single line.
2. ^” is for match any thing expect in regexp and * is for match from Zero (0) to all.

Sree Mereddy

Hi

I am trying to capture a value between ;90004; and ” style=
90004 keeps changing depending on the selection of data from data file with each iteration.
The full string is ;90004;ea98f132-edeb-4ebe-8efe-684cb949c11b” style=

I tried the following

//”RegExp=90004;(.*?)\”\\ \\ \\ style”,
//”RegExp=#####;(.*?)\”\\ \\ \\ style”,
“RegExp=#####;(.*?)\”\\ \\ \\ style”,
SEARCH_FILTERS,
“Scope=Body”,
“IgnoreRedirections=No”,
LAST);

Any help is much appreciated.

Thanks
Sree.

Sureshkumar

Try this,

web_reg_save_param_regexp(
“ParamName=Correlatetry”
“Regexp=\”([0-9]+)\”,\”[a-z0-9]+\””
Last
);

Daniel Spavin

Hi Sree,

Try this:

Ken

I have update 11.52, but am not successful in using multiple capture groups. Are there additional options needed when trying to use this strategy. I tried variations on the group setting, but it does not look like you can capture more than one at a time to put in a variable. At least, I could not do what is proposed above. I just opted for two variables with the same reg exp, but the portion I am interested in placed in parentheses. And I could not find a reference for this in the What’s new section of the help for 11.52.

@LR Guy – Have you tried either to force it to not be greedy for that last word problem, or using the \w word character indicator in your regular expression?

LR Guy

Hi,
How would you correlate the last word of a question when you have different questions? I am trying to correlate the last word of the sentence because that is an answer for each question. There are several questions but the webpage will ask one at a time. So far what I have done:
Correlated the questions.
Tried to correlate last word by using space in left boundary and “?” as right boundary. This is because the questions will be different and in a different lengths. The Right boundary will always be “?” because these are questions.

Any help would be appreciated.

Thank you.

Raju

This is some what complicated code.

Solution: web_reg_save_param_regexp(“ParamName=ParamValue”,”RegExp=rows”:\[\[“[^”\r\n]*”,”([A-Z]{3})”,”[^”\r\n]*”,”[^”\r\n]*”,”[^\/]+\/[\d]+?\/2011″,”[A-Za-z]*”,”[^”\r\n]*”,”[^”\r\n]*”,”([^”\r\n]*)”,”[^”\r\n]*”,”([^”\r\n]*)”,LAST);

Stuart Moncrieff

Check out http://regexpal.com/ as a good way of developing and testing your regular expressions.