Function Reference

REGEXP_LIKE

Checks whether a string contains a match for a regular expression.

PostgreSQL 17.5
REGEXP_LIKE(string, pattern[, flags])

Parameters

stringtext
String to search in
patterntext
Regular expression
flagstextoptional
Flags, for example i to ignore case

Return value

true or false; NULL if string or pattern is NULL

Examples

Case-sensitive and case-insensitive

PostgreSQL 17.5
SELECT REGEXP_LIKE('PostgreSQL', 'sql') AS case_sensitive,
	REGEXP_LIKE('PostgreSQL', 'sql', 'i') AS ignore_case;
case_sensitiveignore_case
falsetrue

Users with Gmail or Hotmail

PostgreSQL 17.5
SELECT name,
	email
FROM Users
WHERE REGEXP_LIKE(email, '@(gmail|hotmail)\.com$')
LIMIT 5;
nameemail
Bruce Willisbarjam@hotmail.com
Jennifer Lopezbarjam@hotmail.com
Harrison Fordkostas@hotmail.com
Michael Douglastimtroyr@hotmail.com
Catherine Zeta-Jonesflakeg@hotmail.com

Details

The function appeared in PostgreSQL 15. It does the same as the ~ operator (and ~* to ignore case). A match is searched anywhere in the string: to check the whole string, add ^ and $ to the pattern.

See also