Function Reference

REGEXP_LIKE

Checks whether a string matches a regular expression.

MySQL 8.1
REGEXP_LIKE(expr, pattern[, match_type])

Parameters

exprVARCHAR
String to check
patternVARCHAR
Regular expression
match_typeVARCHARoptional
Match flags, for example c for case-sensitive matching

Return value

1 if there is a match, otherwise 0; NULL if expr or pattern is NULL

Examples

Case-insensitive and case-sensitive check

MySQL 8.1
SELECT REGEXP_LIKE('Anna', '^an') AS ignore_case,
	REGEXP_LIKE('Anna', '^an', 'c') AS match_case;
ignore_casematch_case
10

Hotmail or Outlook email

MySQL 8.1
SELECT name,
	email
FROM Users
WHERE REGEXP_LIKE(email, '@(hotmail|outlook)[.]com$');
nameemail
Bruce Willisbarjam@hotmail.com
Jennifer Lopezbarjam@hotmail.com
Samuel L. Jacksonmoonlapse@outlook.com
Harrison Fordkostas@hotmail.com
Steve Martinnelson@outlook.com
Michael Douglastimtroyr@hotmail.com
Catherine Zeta-Jonesflakeg@hotmail.com

Details

The match is searched anywhere in the string. To check the whole string, start the pattern with ^ and end it with $. Case sensitivity depends on the collation of the string by default; in the training databases the case is ignored.

The flags in match_type can be combined; if they contradict each other, the last one wins:

FlagDescription
cCase-sensitive matching
iCase-insensitive matching
mMultiline mode: ^ and $ match the start and end of each line of text
nThe dot . also matches a line break
uOnly \n is treated as a line ending

See also