rxpos()

Function group Execute on client Platform(s)
String NO All

Syntax

rxpos(rx,str,igncase,words,mchlen[,captureRow])

Description

Returns position of characters matching regular expression rx in str, or zero for no match; sets mchlen to length of match. igncase and words are Boolean, true for ignore case or only match whole words.

The optional parameter captureRow has been added to PCRE2 regular expressions (the default from Studio 10.2). You can pass this a row variable that returns the captured groups resulting from the regular expression match operation. This is a standard feature of regular expressions – groups correspond to the parts of the regular expression contained in parentheses (provided that the open parenthesis is not followed by ?: indicating a non-capturing group). Groups can also optionally be named, and they are numbered 1 to n, with various rules regarding duplication when using the | operator. For example:

  1. When rxpos() locates nothing, it sets captureRow to empty.

  2. When rxpox() locates something, and the captureRow parameter is supplied, it adds a column to the captureRow for each captured group, where the column name is G<n> for group number n where the group is not named, or the group name.

The following examples will illustrate this:

Calculate cString as  "2017-01-02"
Do rxpos("^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$",cString,0,0,cLen,cRowReturns cOffset

After executing the above line, cRow is a row with three columns named year, month, and day, with the values 2017, 01 and 02, respectively.

Calculate cString as  "hey_test_ho"
Do rxpos("(hey|ho)_test_(ho|hey)",cString,0,0,cLen,cRowReturns cOffset

After executing the above line, cRow is a row with two columns named G1 and G2, with the values hey and ho.

You can mix named and unnamed capture groups.