6.8.2.11 Result Function

Syntax

result (expression)

Description

The result function returns a string matched by the last match statement. If the value of the expression is 0, result returns the string matched by the entire regular expression. Otherwise, the result function returns the string matched by the n'th \(...\) in the regular expression, where n is the value of expression.

If there was no previous match function, or the last match was not successful, the result function returns an empty string.

The match and result functions are useful in extracting substrings from a string.

Example

The following example extracts an area code from a phone number

match(phone,"(\([0-9]\{3\}\))[0-9]\{3\}-[0-9]\{4\}")

result(1)