MySQL REGEXP Operator

In MySQL, The REGEXP operator returns whether a string matches a regular expression.

REGEXP is the same as RLIKE.

REGEXP Syntax

Here is the syntax of the MySQL REGEXP operator:

str REGEXP regexp

Parameters

str
Required. The string to be tested.
regexp
Required. The regular expression to which the string str is to be matched.

Return value

REGEXP returns 1 if the string str matches the gaven regular expression regexp, otherwise it returns 0.

If any parameter is NULL, REGEXP returns NULL.

REGEXP performs a Case-insensitive matching.

REGEXP Examples

Here are some examples of MySQL CHAR() function.

SELECT
    'hello' REGEXP '^[a-z]+$',
    'hello' REGEXP '^[A-Z]+$',
    '12345' REGEXP '[0-9]+$',
    '12345' REGEXP '^\\d+$',
    '123ab' REGEXP '^\\d*$',
    '123ab' REGEXP '^.*$'\G
'hello' REGEXP '^[a-z]+$': 0
'hello' REGEXP '^[A-Z]+$': 0
 '12345' REGEXP '[0-9]+$': 0
  '12345' REGEXP '^\\d+$': 0
  '123ab' REGEXP '^\\d*$': 1
    '123ab' REGEXP '^.*$': 0