Regular Expressions in LoadRunner
April 15, 2008 – 7:24 pmDmitry Motevich posted a challenge for getting regular expressions working in LoadRunner. Regular expressions in C isn’t pretty, but here it is:
I’ll assume you are running on Windows.
- First, download the Binaries and Developer Files for PCRE (Perl Compatible Regular Expressions):
http://gnuwin32.sourceforge.net/packages/pcre.htm - Unzip into c:\pcre
- Modify c:\pcre\include\pcre.h by commenting out the include for stdlib.h:
//#include <stdlib.h>
- In your LoadRunner script, add to globals.h:
#include "c:\\pcre\\include\\pcre.h"
- In LR script, add:
lr_load_dll("c:\\pcre\\bin\\pcre3.dll");
Here is an example that does a simple regex:
Action()
{
pcre *re;
const char *error;
int erroffset;
int rc;
int ovector[30];
lr_load_dll("c:\\tools\\pcre\\bin\\pcre3.dll");
re = pcre_compile(
"^A.*Z", /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
NULL); /* use default character tables */
rc = pcre_exec(
re, /* result of pcre_compile() */
NULL, /* we didn't study the pattern */
"ABCXYZ", /* the subject string */
6, /* the length of the subject string */
0, /* start at offset 0 in the subject */
0, /* default options */
ovector, /* vector of integers for substring information */
30); /* number of elements (NOT size in bytes) */
lr_message("rc=%d",rc);
return 0;
}
Like I said, regex in C isn’t pretty
One Response to “Regular Expressions in LoadRunner”
Hello, Charlie!
You’ve done a great work, I appreciated it.
Based on your and Tim Koopmans’ solutions, I created a functions to work easily with RegExp in LoadRunner.
The solution is located here:
Examples on LoadRunner Regular Expressions
So, I hope that you’ll change your opinion and you’ll make sure that RegExp in C is pretty
–
Dmitry Motevich
By Dmitry Motevich on May 1, 2008