REGEXP()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns a boolean indicating if a string value is matched by a regular expression.
USAGE
REGEXP(check, match)
Argument Name | Description |
---|---|
| The string to search |
| The regular expression match string |
DETAILS
REGEXP()
is a function that 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 argument is NULL
.
The function call REGEXP(x, y)
behaves in exactly the same manner as the operator x REGEXP y
.
EXAMPLES
SELECT REGEXP('This is a test', 't.sts?') AS result1,
REGEXP('3', 3) AS result2;
+---------+---------+
| result1 | result2 |
+---------+---------+
| 1 | 1 |
+---------+---------+
SELECT REGEXP('Hello there', '^e');
+-----------------------------+
| REGEXP('Hello there', '^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 REGEXP(description, '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 REGEXP(description, '\\.');
+-------------+---------+
| description | example |
+-------------+---------+
| B. Doz. | 13 |
+-------------+---------+