JavaScript Functions > Alphabetical Listing of Utility Functions (lr) > lr.saveParamRegexp

lr.saveParamRegexp

Finds a match or matches to a regular expression in a buffer, and saves the capture group to a parameter.

Example String and Parameter Functions

Syntax

lr.saveParamRegexp ( {object} );	

JavaScript Object

{
   bufferToSearch: "<string>",
   bufferSize: <number>,
   regExp: "<search_string>"|{value: "<search_string>", flag: "IC" }, 
   ordinal: "<string>",
   resultParam: "<string>"
} 

Arguments

Property Name Description
bufferTosearch The buffer in which to search for matches. The buffer can contain binary data.
bufferSize In bytes.
regExp A regular expression with exactly one capture group.
flag Flag IC means not case sensitive. For example, regExp: |{value: "(r*)", flag: "IC" } matches 'RR' and 'rRr'.
ordinal

The 1-based location of the match to find. For example, "ordinal=2" finds the second match.

A value of 0 indicates to find all matches and save the capture strings in a parameter array. The symbol All can be used in place of 0. For example, "ordinal=All".

ResultParam The name of the parameter or parameter array to save the matches in.

lr.saveParamRegexp searches inside a buffer for a match or matches to a regular expression.

If ordinal is an integer greater than 0 and at least that number of matches is found, a parameter is created with the name specified by the ResultParam argument. The value of the parameter is the capture group of the match.

If ordinal is ALL (0) and at least one match is found, a parameter array is created. The values of the parameters are the capture groups of the matches.

The parameter is not created if either no matches are found or if an ordinal value is specified and fewer matches are found. For example, if "ordinal=3" and only 2 matches are found, the parameter is not created.

If there are multiple calls with the same result parameter, each call overwrites the previous value.

The last result parameter value from a call to lr.saveParamRegexp in an iteration persists between iterations. The first call in an iteration overwrites the previous value.

See also: Example of Parameter Array Use.

Return Values

Not applicable

Parameterization

Standard parameterization is not available for this function.

Concept Link IconSee Also

Example

function Action(){
    var bufferToSearch =
        "_a_XX11YY_b_XX22YY_c_XX33YY_d_XX44YY_abcde";

    var matchCt, ord;
    var arrayMemberValue;

    lr.saveParamRegexp ({
        bufferToSearch : bufferToSearch,
               bufferSize: bufferToSearch.length,
               regExp:"(XX..YY)",
               ordinal:"All",
               resultParam :"reMatchesParam"});

    matchCt = lr.paramarrLen("reMatchesParam");

    lr.message(matchCt + " match(es) found.");

    for (ord=1; ord <= matchCt; ord++){
        arrayMemberValue = lr.paramarrIdx("reMatchesParam",ord);
        lr.message("Member "+ord+" value: "+arrayMemberValue);
    }

    return 0;
}