regexp_like

Tests whether a string contains a regular expression match.

Syntax

regexp_like(<string>, regex => <regex>)

Arguments

ArgumentTypeDescription
<string>stringString to search.
regexstringConstant. Regular expression. Must be valid and non-NULL.

Returns

Returns boolean: TRUE if a match is found, otherwise FALSE. Returns NULL if the input is NULL.

Usage notes

The pattern can match anywhere in the input. Use ^ and $ to require a whole-string match. . also matches newlines.

Examples

Check whether each event ID has the evt- prefix followed by exactly six digits:

VALUES ('evt-000017'), ('evt-42'), ('order-000017')
SELECT $0 AS event_id
SELECT event_id, regexp_like(event_id, regex => '^evt-[0-9]{6}$') AS valid_id
+--------------+----------+
| event_id     | valid_id |
+--------------+----------+
| evt-000017   | true     |
| evt-42       | false    |
| order-000017 | false    |
+--------------+----------+