regexp_match()

A function returning the match for a regular expression

regexp_match() is a system function returning the first substring to match a POSIX regular expression.

regexp_match() was added in PostgreSQL 10.

Usage

regexp_match ( string text, pattern text [, flags text ] ) → text[]

regexp_match() is essentially a simplified version of regexp_matches(). A list of flags which can be used with regexp_match() is available in the PostgreSQL documentation: ARE Embedded-Option Letters.

Change history

Examples

Basic usage example for regexp_match():

postgres=# SELECT regexp_match('foobarboo', '.oo');
 regexp_match
--------------
 {foo}
(1 row)

The 'g' flag cannot be used with regexp_match():

postgres=# SELECT regexp_match('foobarboo', '.oo', 'g');
ERROR:  regexp_match does not support the global option
HINT:  Use the regexp_matches function instead.

Categories

String manipulation, System function

See also

regexp_matches()