regexp_firstsearch()

Scalar. Returns the first occurrence of a POSIX regular expression pattern found in a given string.

Syntax

regexp_firstsearch ( string, regex )

Parameters

string

A string.

regex

A POSIX regular expression pattern. This pattern is limited to the Perl syntax.

Usage

Returns the first occurrence of a POSIX regular expression pattern found in a given string. If string does not contain a match for the pattern, or if the specified pattern is not a valid regular expression, the function returns NULL. One or more subexpressions can be included in the pattern, each enclosed in parentheses. If string contains a match for the pattern, the function only returns the parts of the pattern specified by the first subexpression. The function returns a string.

The function works with UTF-8 strings if the -U server option is specified.

Example

regexp_firstsearch('aaadogaaa', '[b-z]*') returns 'dog'.

regexp_firstsearch('h', '[i-z]*') returns NULL.

regexp_firstsearch('aaaaabaaaabbbaaa', '[b-z]*') returns 'b'.