REGEXP
This page is part of MariaDB's Documentation.
The parent of this page is: SQL Operators for MariaDB Xpand
Overview
Regular Expression matching.
USAGE
check REGEXP match
Value Name | Description |
---|---|
| The string to search |
| The regular expression match string |
DETAILS
The REGEXP
operator matches a regular expression match
string against a check
string. A 1
(true) is returned if they match, otherwise a 0
(false) is returned.
The match
string must be a valid regular expression.
The regular expression is not required to match the full ''check`` value unless you anchor the expression to match at the start and end of the string.
Regular expression matching respects multiple character boundaries, so specifying a .
(dot) can match a multi-byte encoded character and will never partially match individual bytes within multi-character encoded strings.
Any non-string arguments are converted to their string representation.
A NULL
is returned if either input value is NULL
.
The operator x REGEXP y
behaves in exactly the same manner as the function call REGEXP(x, y)
.
SYNONYMS
The following are synonyms for REGEXP:
RLIKE
EXAMPLES
SELECT 'This is a test' REGEXP 't.sts?' AS result1,
'3' REGEXP 3 AS result2;
+---------+---------+
| result1 | result2 |
+---------+---------+
| 1 | 1 |
+---------+---------+
SELECT 'Hello there' REGEXP '^e';
+---------------------------+
| 'Hello there' REGEXP '^e' |
+---------------------------+
| 0 |
+---------------------------+
CREATE TABLE regexp_example (
description VARCHAR(20),
example INT
);
INSERT INTO regexp_example VALUES
('Everything', 42),
('Dalmations', 101),
('Agent', 99),
('B. Doz.', 13),
('CPU', 64);
SELECT *
FROM regexp_example
WHERE description REGEXP 'ing$|^....t';
+-------------+---------+
| description | example |
+-------------+---------+
| Everything | 42 |
| Agent | 99 |
+-------------+---------+
-- Note that a backslash needs to be doubled due to string escaping
SELECT *
FROM regexp_example
WHERE description REGEXP '\\.';
+-------------+---------+
| description | example |
+-------------+---------+
| B. Doz. | 13 |
+-------------+---------+