util.Regexp.getMatchIndex

Returns the starting and ending position of the first (leftmost) match of the regular expression in the subject.

Syntax

util.Regexp.getMatchIndex(
  subject STRING
 )
  RETURNS (INTEGER, INTEGER)
  1. subject is the subject to be scanned.

Usage

The getMatchIndex() method returns the position of the first occurrence of the string matching the regular expression, in the string passed as parameter.

The method returns (NULL,NULL), if the passed string does not contain any matching string for the current regular expression.

The positions are expressed in byte units or character units, depending on the current length semantics (FGL_LENGTH_SEMANTICS).

Example

IMPORT util
MAIN
    DEFINE re util.Regexp
    DEFINE s,e INTEGER
    DEFINE arr DYNAMIC ARRAY OF STRING
    LET re = util.Regexp.compile(`[ABC]XX`)
    CALL re.getMatchIndex("ZZZZBXXZZ") RETURNING s,e
    DISPLAY s, e
END MAIN
Output:
          5          7