StrRegexCompile Function

Action

Compiles a regular expression and applies the resulting automaton (compiled byte code) to a handle for later use by StrRegexExecute, StrRegexSubst and StrRegexClose.

This function is very advantageous when you need to reuse the same regular expression over and over again because it speeds up the execution of the BDL-Script.

Include file

Kernel.bdh

Syntax

StrRegexCompile( inout hRegex   : number,
                 in    sRegex   : string,
                 in    nBufSize : number optional): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hRegex Variable receiving the handle to the compiled regular expression
sRegex Regular expression
nBufSize Size of the buffer used to store the compiled regular expression (optional). Default value is 2048.

Example

dcltrans
  transaction TMain
  var
    hRegex                   : number;
    sRegex, sSource, sTarget : string;
    match                    : boolean;
  begin
    sSource := "SessionIDTest.asp?SessionID=SID8:44:43&"
               "Param2=Value2";
    sRegex := "SessionID=\(SID[0-9:]+\)";
    write("source = "+sSource); writeln;
    write("regex = "+sRegex); writeln;
    StrRegexCompile(hRegex, sRegex);
    match := StrRegexExecute(hRegex, sSource);

    if match then
      StrRegexSubst(hRegex, "\1", sTarget, STRING_COMPLETE);
      write("match: "+sTarget); writeln;
    else
      write("no match"); writeln;
    end;

    StrRegexClose(hRegex);
  end TMain;

Output

source = SessionIDTest.asp?SessionID=SID8:44:43&Param2=Value2
regex = SessionID=\(SID[0-9:]+\)
match: SID8:44:43

Sample scripts

WebRegularExpressions01.bdf