This document introduces the basic syntax and examples of regular expression functions.
CLS supports the following regular expression functions:
Function | Syntax | Description |
---|---|---|
regexp_extract_all | regexp_extract_all(x, regular expression) | Extracts the substrings that match a specified regular expression from a specified string and returns a collection of all matched substrings. |
regexp_extract_all(x, regular expression, n) | Extracts the substrings that match a specified regular expression from a specified string and returns a collection of substrings that match the target capture group. | |
regexp_extract | regexp_extract(x, regular expression) | Extracts and returns the first substring that matches a specified regular expression from a specified string. |
regexp_extract(x, regular expression, n) | Extracts the substrings that match a specified regular expression from a specified string and returns the first substring that matches the target capture group. | |
regexp_like | regexp_like(x, regular expression) | Checks whether a specified string matches a specified regular expression. |
regexp_replace | regexp_replace(x, regular expression) | Deletes the substrings that match a specified regular expression from a specified string and returns the substrings that are not deleted. |
regexp_replace(x, regular expression, replace string) | Replaces the substrings that match a specified regular expression in a specified string and returns the new string after the replacement. | |
regexp_split | regexp_split(x, regular expression) | Splits a specified string into multiple substrings by using a specified regular expression and returns a collection of the substrings. |
The regexp_extract_all
function is used to extract the substrings that match a specified regular expression from a specified string.
Extract the substrings that match a specified regular expression from a specified string and return a collection of all matched substrings.
regexp_extract_all(x, regular expression)
Extract the substrings that match a specified regular expression from a specified string and return a collection of substrings that match the target capture group.
regexp_extract_all(x, regular expression, n)
Parameter | Description |
---|---|
x | The parameter value is of the varchar type. |
regular expression | The regular expression that contains capture groups. For example, (\d)(\d)(\d) indicates three capture groups. |
n | The nth capture group. n is an integer that starts from 1. |
Array
Extract all numbers from the value of the http_protocol
field.
Query and analysis statement
* | SELECT regexp_extract_all(http_protocol, '\d+')
Query and analysis result
The regexp_extract
function is used to extract the first substring that matches a specified regular expression from a specified string.
Extract and return the first substring that matches a specified regular expression from a specified string.
regexp_extract(x, regular expression)
Extract the substrings that match a specified regular expression from a specified string and return the first substring that matches the target capture group.
regexp_extract(x, regular expression, n)
Parameter | Description |
---|---|
x | The parameter value is of the varchar type. |
regular expression | The regular expression that contains capture groups. For example, (\d)(\d)(\d) indicates three capture groups. |
n | The nth capture group. n is an integer that starts from 1. |
Varchar
http_protocol
fieldQuery and analysis statement
* | SELECT regexp_extract_all(http_protocol, '\d+')
Query and analysis result
request_uri
field and count the number of times each file is accessedQuery and analysis statement
* | SELECT regexp_extract(request_uri, '.*\/(index.*)', 1) AS file, count(*) AS count GROUP BY file
Query and analysis result
The regexp_like
function is used to check whether a specified string matches a specified regular expression.
regexp_like (x, regular expression)
Parameter | Description |
---|---|
x | The parameter value is of the varchar type. |
regular expression | Regular expression. |
Boolean
Check whether the value of the server_protocol
field contains digits.
Query and analysis statement
* | select regexp_like(server_protocol, '\d+')
Query and analysis result
The regexp_replace
function is used to delete or replace the substrings that match a specified regular expression in a specified string.
Delete the substrings that match a specified regular expression from a specified string and return the substrings that are not deleted.
regexp_replace (x, regular expression)
Replace the substrings that match a specified regular expression in a specified string and return the new string after the replacement.
regexp_replace (x, regular expression, replace string)
Parameter | Description |
---|---|
x | The parameter value is of the varchar type. |
regular expression | Regular expression. |
replace string | Substring that is used to replace the matched substring. |
String
Delete the version number in the value of the server_protocol
field and calculate the number of requests for each communication protocol.
Query and analysis statement
* | select regexp_replace(server_protocol, '.\d+') AS server_protocol, count(*) AS count GROUP BY server_protocol
Query and analysis result
The regexp_split
function is used to split a specified string into multiple substrings and return a collection of the substrings.
regexp_split (x, regular expression)
Parameter | Description |
---|---|
x | The parameter value is of the varchar type. |
regular expression | Regular expression. |
Array
Split the value of the server_protocol
field with forward slashes (/).
Query and analysis statement
* | select regexp_split(server_protocol, '/')
Query and analysis result
Was this page helpful?