I quite literally stole this idea from Charlie at PerformanceEngineering in which he posted a response to a challenge by Dmitry on how to get regular expressions up and running within LoadRunner.
I’m a huge fan of regex, and thanks to these guys, now have a way of implementing at least pattern matching with LoadRunner. Ideally I’d like to be able to include pattern matching & replacing, like Ruby or Perl does in one line but for now am happy for pattern matching.
Read on for the changes I made to Charlies code to abstract matching functionality and call it as a function within other LoadRunner actions.
First thing, follow these instructions posted by Charlie
# First, download the Binaries and Developer Files for PCRE (Perl Compatible Regular Expressions):
http://gnuwin32.sourceforge.net/pakages/pcre.htm# Unzip (both archives) into
c:\pcre# Modify
c:\pcre\include\pcre.hby commenting out the include for stdlib.h:
//#include# In your LoadRunner script, add to globals.h:
#include "c:\\pcre\\include\\pcre.h"
Then from here on I differ slightly by adding a couple of functions to my vuser_init as per the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | vuser_init() { return 0; } buffer() { // This will save a 2MB buffer of the response body when called. web_set_max_html_param_len("2097152"); //2MB buffer web_reg_save_param("buffer", "LB=", "RB=", "Search=Body", LAST); return 0; } match(const char *string, char *pattern) { // This will return 1 for a match, or 0 for a non-match / error int status; pcre *re; lr_load_dll("c:\\pcre\\bin\\pcre3.dll"); if (regcomp(&re, pattern) != 0) { return(0); /* Report error. */ } status = regexec(&re, string, (size_t) 0, NULL, 0); regfree(&re); if (status != 0) { return(0); /* Report error. */ } return(1); } |
Then from your main action you can call that match function in a Perl’ish kind of way as per:
1 2 | rc = match(lr_eval_string("{buffer}"),"[\\w-]+"); lr_message("Return Code = %d",rc); |
Make sure you create an int to store your return code.
Attached are example vuser_init and actions for you.
regex vuser_init :: regex action
Thanks Charlie and Dimitry! Would like to see this challenge extended to search & replace functionality using regex …

Thats awesome Koops…
Hello, Tim.
I appreciated your efforts on working with Regular Expressions in LoadRunner.
I moved forward Charlie’s and your ideas on LoadRunner RegExps. So, now we can use LR RegExp to match subpatterns and to capture (=to extract) all matched substrings.
The solution is located here:
Examples on LoadRunner Regular Expressions
For my own reference, you can also get regex pattern matching with this approach. You need to comment out
//#includein the pcreposix.h header for this to work:Regards,
Tim Koopmans
Tim,
I found the pcre files at the following site:
http://gnuwin32.sourceforge.net/packages/pcre.htm
Hi, I want to encrypt the password while passing these parameterized values within the script. I am basically looking to find if we have a similar function in LoadRunner (as we have in QTP, SetSecure (“test123″))?
Appreciate, if anyone can respond.
Thanks!
Hi Satish, check out the lr_decrypt function, this is probably what you are after …
Cheers,
Tim
[...] been identified how to enable Regular Expressions in LoadRunner. A big thanks to Charlie, Tim for getting this working, and Dmitry for proposing the [...]