Regular Expressions in LoadRunner

Dmitry 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.

  1. First, download the Binaries and Developer Files for PCRE (Perl Compatible Regular Expressions):
    http://gnuwin32.sourceforge.net/packages/pcre.htm
  2. Unzip into c:\pcre
  3. Modify c:\pcre\include\pcre.h by commenting out the include for stdlib.h:
    //#include <stdlib.h>
  4. In your LoadRunner script, add to globals.h:
    #include "c:\\pcre\\include\\pcre.h"
  5. 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

Comments

LoadRunner RegExp

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