regex_match(X;L;Y;I)

Returns the substring corresponding to a particular match of a specified regular expression within a given string.

Syntax

regex_match(X;L;Y;I)

Input

Argument Type Description
X text A valid regular expression to search for in the string Y
Note: '\' is the escape character for strings, and '\' is also the escape character for regex functions. Therefore, in order to represent a special character in X, you need a double backslash ('\\'). See examples below.

An exception to this rule is that as of version 17.07, square brackets ([]) and '@' no longer need to be escaped with '\' in string literals. They may be escaped, but the escaping will not be preserved when expressions are deferred, such as in a QuickApp. Therefore, escaping should be avoided for these characters.

L text A list of one or more string options. (L may be omitted.)

These options include:

  • 'icase' - ignore case
  • 'lit' - treat X as a literal string rather than a regular expression
  • 'nl' - treat the newline character as a line delimiter
  • 'ug' - default all operators to be ungreedy
  • 'right' - make matches right-associative
  • 'first' - find only the first match - this is also faster if it is necessary to determine if there is any match at all
  • 'tre' - use a TRE regex engine (default) (Available as of prod-9.)
  • 'pcre' - use a Perl Compatible Regular Expression (PCRE) engine (Available as of prod-9.)
The 'tre' and 'pcre' options refer to the back-end regex engine used for matching. If both options are specified, or if neither option is specified, the TRE engine will be used.
Note: The 'lit' and 'right' options cannot be used in conjunction with the 'pcre' option.
Y text The string within which to search for the regular expression X

A scalar value or the name of a column

I integer An index corresponding to a particular instance of the regular expression X within the given string Y

The index I is 1-based (i.e., the first match has index 1).

A negative index counts back from the end of the string (i.e., I=-1 refers to the last match).

Return Value

Returns the text value corresponding to the I'th match of the regular expression X within the string Y.

If Y is N/A, the result is N/A.

Sample Usage

regex options string index regex_match(regex;options;string;index)
'a(b|c|d)' 'Abracadabra' 1 'ac'
'a(b|c|d)' 'icase' 'Abracadabra' -4 'Ab'
'a(b|c|d)' '' 1 ''
'\\(hi\\)' '(hi)' 1 '(hi)'
'\\\\' '\\' 1 '\'

Additional Information

  • 1010data supports POSIX standard regular expressions. See Regular Expressions for more information.