0

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?

Karl Wilbur
  • 5,898
  • 3
  • 44
  • 54
  • sorry, but neither LoadUIWeb, nor WebLoad are having anything with JMeter correct the tags please – Yuri G Mar 15 '17 at 23:00

1 Answers1

1

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.

Karl Wilbur
  • 5,898
  • 3
  • 44
  • 54
  • Thanks Karl, but If we received the following 3 response in a page: index=2&Roll_ID=9572&NAME=ANDY&LastName=MURRAY&amp& index=1&Roll_ID=7875&NAME=TOM&LastName=SHAW&amp& index=7&Roll_ID=8343&NAME=EMA&LastName=WINSTON&amp&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. – ABHISEK ACHARYA Mar 16 '17 at 08:20
  • Ah, gotcha. Well, the regex I wrote above will still capture `index` without modification. However, if you need to capture values that contain '&', and all of your key-value separaters are always going to be encoded as '&', then I think you should use a lookahead assertion for `&` rather than a character class `[^&]`. Your regex would look like: `/KeyName=(.*?(?=&|$))/` – Karl Wilbur Mar 16 '17 at 12:58
  • Thanks... got it...... However the following code also did the job for me.. var str = "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"; var re = /index=(.*?)&Roll_ID=.*?&NAME=.*?&LastName=.*?&Birthday/g; var match_result = re.exec(str); var index_val = match_result[1]; InfoMessage(index_val); Output: 7 – ABHISEK ACHARYA Mar 17 '17 at 05:53