All pages
Powered by GitBook
1 of 1

Loading...

REGEXP_SUBSTR

Return the substring matching a regex. This function extracts the actual part of the string that matches the given pattern.

Syntax

REGEXP_SUBSTR(subject,pattern)

Description

Returns the part of the string subject that matches the regular expression pattern, or an empty string if pattern was not found.

The function follows the case sensitivity rules of the effective . Matching is performed case insensitively for case insensitive collations, and case sensitively for case sensitive collations and for binary data.

The collation case sensitivity can be overwritten using the (?i) and (?-i) PCRE flags.

MariaDB uses the library for enhanced regular expression performance, and REGEXP_SUBSTR was introduced as part of this enhancement.

The variable addresses the remaining compatibilities between PCRE and the old regex library.

Examples

This page is licensed: CC BY-SA / Gnu FDL

SELECT REGEXP_SUBSTR('ab12cd','[0-9]+');
-> 12

SELECT REGEXP_SUBSTR(
  'See https://mariadb.org/en/foundation/ for details',
  'https?://[^/]*');
-> https://mariadb.org
collation
PCRE regular expression
default_regex_flags