StrRegexSubst Function

Action

Substitutes matched portions into a template string sSubst. The result is then stored in sTarget. Call this function if you want to easily extract multiple parts from the source string.

Include file

Kernel.bdh

Syntax

StrRegexSubst( in  hRegex     : number,
               in  sSubst     : string,
               out sTarget    : string,
               in  nMaxTarget : number ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hRegex Valid handle to a compiled regular expression. This handle must have been generated with a previous call to StrRegexCompile.
sSubst String into which matched portions are substituted
sTarget String which receives the result of the substitution string
nMaxTarget Size of sTarget

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