How to use Regular Expression Extractor while correlating using javascript in Webload PT tool?

349 Views Asked by At

I am able to extract a value from a given expression by using the Left and Right boundary in Webload, but I am unable to extract a particular value (for example, index) from the following expression using regular expression extractor:

index=2&Roll_ID=95372&NAME=ANDY&LastName=MURRAY&birthday

If we received the following 3 response in a page:

index=2&Roll_ID=9572&NAME=ANDY&LastName=MURRAY&a‌​mp& index=1&Roll_ID=7875&NAME=TOM&LastName=SHAW&amp& index=7&Roll_ID=8343&NAME=EMA&LastName=WINSTON&a‌​mp&Birthday

So, what must be our regular expression to catch the index value (7) from the last response as it has an additional tag Birthday As I believe in this case we have to pass the regular expressions for Roll ID, Name and Last Name as we don't know which one contains birthday....although we are extracting the value of Index.

Like in LoadRunner we write the regular expression to capture the index as following:

index=(.*?)&Roll_ID=.*?&NAME=.*?&LastName=.*?&Birthday

In Webload how can we write extract this value?

Is there any inbuilt function available in Webload to use regular expression extractor?

Or how can we extract this value using JavaScript code?

1

There are 1 best solutions below

3
On

Here is a quick JavaScript example:

var str = "index=2&Roll_ID=95372&NAME=ANDY&LastName=MURRAY&"
var match_result = str.match(/index=([^&]*?)/);
var index_val  =  match_result[1];

For this example, I am assuming that this is going to be a standard URI query string. So, in the match() regex I am looking for index= explicitly and then grabbing the value (anything not a "&" character, the *? stops matching at the first occurrence of "&").

For HTML encoded query strings, you should would need to do a lookahead for "&" to determine the end of your value match.