tencent cloud

Cloud Log Service

Regular Expression Function

Download
Focus Mode
Font Size
Last updated: 2026-05-14 21:04:24
This section describes the basic syntax and examples of regular expression functions.
CLS supports the following regular expression functions:
Function Name
Syntax
Description
regexp_extract_all(x, regular expression)
Extracts substrings matching a regular expression from the target string and returns a collection of all matching substrings.
regexp_extract_all(x, regular expression, n)
Extracts substrings matching a regular expression from the target string and returns a collection of substrings matching the target capturing group.
regexp_extract(x, regular expression)
Extracts and returns the first substring matching a regular expression from the target string.
regexp_extract(x, regular expression, n)
Extracts substrings matching a regular expression from the target string and returns the first substring matching the target capturing group.
regexp_like (x, regular expression)
Determines whether the target string matches a regular expression.
regexp_replace (x, regular expression)
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 string)
Replace the substrings that match a specified regular expression in a specified string and return the new string after the replacement.
regexp_split (x, regular expression)
Splits the target string with a regular expression, and returns a collection of substrings after splitting.

regexp_extract_all Function

The regexp_extract_all function is used to extract a collection of substrings matching a regular expression from the target string.

Syntax

Extract substrings matching a regular expression from the target string and return a collection of all matching substrings.
regexp_extract_all(x, regular expression)
Extract substrings matching a regular expression from the target string and return a collection of substrings matching the target capturing group.
regexp_extract_all(x, regular expression, n)

Parameter description

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.

Return value type

Array

Example

Extract all digits in the http_protocol field, where the value of http_protocol is HTTP/1.1.
Query and analysis statement
* | SELECT regexp_extract_all(http_protocol, '\\d+')
Query and analysis result
[1,1]

regexp_extract Function

The regexp_extract function is used to extract the first substring matching a regular expression from the target string.

Syntax

Extract and return the first substring matching a regular expression from the target string.
regexp_extract(x, regular expression)
Extract substrings matching a regular expression from the target string and return the first substring matching the target capturing group.
regexp_extract(x, regular expression, n)

Parameter description

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.

Return value type

Varchar

Example

Example 1. Extract the first number from the value of the http_protocol field

Query and analysis statement
* | SELECT regexp_extract(http_protocol, '\\d+')
Query and analysis result
1

regexp_like

The regexp_like function is used to check whether a specified string matches a specified regular expression.

Syntax

regexp_like (x, regular expression)

Parameter description

Parameter
Description
x
The parameter value is of the varchar type.
regular expression
Regular expression.

Return value type

Boolean

Example

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
TRUE

regexp_replace

The regexp_replace function is used to delete or replace the substrings that match a specified regular expression in a specified string.

Syntax

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

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.

Return value type

String

Example

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
server_protocol
count
HTTP
357
Example 2: Use the * character to replace the digits in the original string hello123world, and use - to connect the parts of the string.
Query and analysis statement
* | SELECT regexp_replace('hello123world', '(hello)(\\d+)(world)', '$1-***-$3') as demo limit 1
Query and analysis result
demo
hello-***-world

regexp_split

The regexp_split function is used to split a specified string into multiple substrings and return a collection of the substrings.

Syntax

regexp_split (x, regular expression)

Parameter description

Parameter
Description
x
The parameter value is of the varchar type.
regular expression
Regular expression.

Return value type

Array

Example

Split the value of the server_protocol field with forward slashes (/).
Query and analysis statement
* | select regexp_split(server_protocol, '/')
Query and analysis result
["HTTP","1.1"]


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback