REGEXFIND

REGEXFIND(regex, text [, flag ] [, NOCASE])

regexA standard Perl regular expression.
textThe text to parse.
flagOptional. Specifies the text to return. If omitted, REGEXFIND returns TRUE or FALSE as to whether the regex was found within the text. If 0, the portion of the text the regex was matched is returned. If >= 1, the text matched by the nth group in the regex is returned.
NOCASEOptional. Specifies a case insensitive search.
Return:REGEXFIND returns a single value.

The REGEXFIND function uses the regex to parse through the text and find matches. The regex must be a standard Perl regular expression.

We use a third-party library -- Perl-compatible Regular Expressions (PCRE2) to support this. See https://www.pcre.org/current/doc/html/pcre2syntax.html for details on the PCRE2 pattern syntax.

Example:

namesRecord := RECORD
STRING20 surname;
STRING10 forename;
STRING10 userdate;
END;
namesTbl := DATASET([{'Halligan','Kevin','10/14/1998'},
                     {'Halligan','Liz','12/01/1998'},
                     {'Halligan','Jason','01/01/2000'},
                     {'MacPherson','Jimmy','03/14/2003'} ],namesRecord);
searchpattern := '^(.*)/(.*)/(.*)$';
search := '10/14/1998';

filtered := namesTbl(REGEXFIND('^(Mc|Mac)', surname));

OUTPUT(filtered); //returns 1 record -- MacPherson, Jimmy
OUTPUT(namesTbl,{(string30)REGEXFIND(searchpattern,userdate,0),
                 (string30)REGEXFIND(searchpattern,userdate,1),
                 (string30)REGEXFIND(searchpattern,userdate,2),
                 (string30)REGEXFIND(searchpattern,userdate,3)});

REGEXFIND(searchpattern, search, 0); //returns '10/14/1998'
REGEXFIND(searchpattern, search, 1); //returns '10'
REGEXFIND(searchpattern, search, 2); //returns '14'
REGEXFIND(searchpattern, search, 3); //returns '1998'

See Also: PARSE, REGEXFINDSET, REGEXREPLACE