REGEXP (also written as RLIKE) is a comparison operator that evaluates whether a character expression matches a regular expression pattern. It returns 1 (true) when the pattern matches and 0 (false) otherwise. REGEXP supports anchors (^, $), character classes ([a-z]), quantifiers (*, +, ?), alternation (|), grouping (()), and escapes (\\). Case sensitivity depends on collation in MySQL; use a *_bin collation for case-sensitive matches. NOT REGEXP negates the result. In contrast to LIKE, REGEXP offers full regular expression power, making it suitable for complex string validations and searches. Performance can degrade on large text columns without indexes. In MySQL 8+, REGEXP uses the International Components for Unicode (ICU) library, enabling Unicode-aware matching.
string_expression
(STRING) - The text to test.pattern_expression
(STRING) - A valid regular expression to compare against.LIKE, RLIKE, REGEXP_LIKE, SIMILAR TO, ~ operator (PostgreSQL)
MySQL 3.23
Yes. In MySQL and MariaDB, REGEXP and RLIKE are synonyms and behave identically.
Yes. Although REGEXP in a WHERE clause only returns true or false, you can still use parentheses for grouping and alternation inside the pattern.
Apply a binary collation to the string column or pattern, for example: `WHERE name COLLATE utf8mb4_bin REGEXP '^Galaxy$'`.
In regular expressions, dot is a wildcard. Escape it with a backslash (\\.) when you want a literal period.