REGEXP()

Overview

Returns a boolean indicating if a string value is matched by a regular expression.

USAGE

REGEXP(check, match)

Argument Name

Description

check

The string to search

match

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.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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 |
+-------------+---------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES