Menu

MySQL RLIKE Operator

Updated on

MySQL RLIKE tests whether a string matches a regular expression. It is an operator synonym for REGEXP, not a function call. In MySQL 8.0.4 and later, both operators are synonyms for REGEXP_LIKE(). See the MySQL regular expression reference.

Syntax

expr RLIKE pattern

expr is the string to test, and pattern is a regular expression.

Example

SELECT
    'Order 123' RLIKE '[0-9]+' AS contains_digits,
    '12345' RLIKE '^[0-9]+$' AS digits_only,
    '123a' RLIKE '^[0-9]+$' AS not_digits;
contains_digits  digits_only  not_digits
---------------  -----------  ----------
1                1            0

The operator returns 1 for a match, 0 for no match, and NULL if either operand is NULL. Regular-expression case behavior follows the operands’ character set and collation. Use REGEXP_LIKE() with a match type when you need to request case-sensitive or case-insensitive matching explicitly.

Advertisement