RLIKE and REGEXP
Warning
SingleStore 9.0 gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 8.9 is recommended for production workloads, which can later be upgraded to SingleStore 9.0.
On this page
RLIKE
and REGEXP
are synonyms.RLIKE
is discussed below.REGEXP
, as both functions work identically.
RLIKE
searches a string for a regular expression pattern.1
if the pattern is found and returns 0
otherwise.
RLIKE
supports the extended and advanced regular expression formats.regexp_
to specify which format you want to use.
Syntax
source_string RLIKE pattern
source_string REGEXP pattern
-
source_
string: A string expression, such as a column name, to be searched. -
pattern: A string literal representing a regular expression.
Examples
The following examples demonstrate how RLIKE
works when the global variable regexp_
is set to 'extended'
.
Call to |
Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following examples demonstrate how RLIKE
works when the global variable regexp_
is set to 'advanced'
.
Call to |
Result |
---|---|
|
|
|
|
|
|
|
|
|
|
Using RLIKE
With a Table
The following example shows how to call RLIKE
once per table row.
SET GLOBAL regexp_format = 'extended';DROP DATABASE IF EXISTS singlestore_docs_example;CREATE DATABASE singlestore_docs_example;USE singlestore_docs_example;CREATE TABLE regexample_table(id INT, text_field TEXT);INSERT INTO regexample_table VALUES (1, 'the'), (2, 'athe'), (3, 'abthe'),(4, 'abcthe'), (5, 'thethe');SELECT id, text_field, text_field RLIKE '..the' FROM regexample_tableORDER BY id;
+------+------------+--------------------------+
| id | text_field | text_field RLIKE '..the' |
+------+------------+--------------------------+
| 1 | the | 0 |
| 2 | athe | 0 |
| 3 | abthe | 1 |
| 4 | abcthe | 1 |
| 5 | thethe | 1 |
+------+------------+--------------------------+
Last modified: April 15, 2024