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;Hotmail or Outlook email
MySQL 8.1
SELECT name,
email
FROM Users
WHERE REGEXP_LIKE(email, '@(hotmail|outlook)[.]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: