Categories:

String Functions (Regular Expressions)

REGEXP

Returns true if the subject matches the specified pattern. Both inputs must be text expressions.

Aliases

RLIKE (2nd syntax)

See also String Functions (Regular Expressions).

Syntax

<subject> REGEXP <pattern>

Usage Notes

  • The function implicitly anchors a pattern at both ends (i.e. '' automatically becomes '^$', and 'ABC' automatically becomes '^ABC$'). To match any string starting with ABC, the pattern would be 'ABC.*'.

  • For more usage notes, see the General Usage Notes for regular expression functions.

Collation Details

Arguments with collation specifications are currently not supported.

Examples

-- Example setup
CREATE OR REPLACE TABLE rlike_test(city varchar(20));
INSERT INTO rlike_test VALUES ('Sacramento'), ('San Francisco'), ('San Jose');

-- Pattern matching with wildcards:
SELECT * FROM rlike_test WHERE city REGEXP 'San* [fF].*';

+---------------+
| CITY          |
|---------------|
| San Francisco |
+---------------+