Updated on 2025-08-14 GMT+08:00

Regular Expression Functions

This section describes regular expression functions, including their syntax, parameters, and usage examples.

Function List

Table 1 Regular expression functions

Function

Description

regexp_extract

Extracts a substring that matches a specified regular expression from a target string.

regexp_like

Checks whether a target string matches a specified regular expression.

regexp_extract_all

Extracts all substrings that match a specified regular expression from a target string.

regexp_replace

Removes or replaces all substring that match a specified regular expression from a target string.

regexp_split

Splits a target string and returns the substrings after splitting.

regexp_extract

This function extracts a substring that matches a specified regular expression from a target string.

  • Extracts and returns the first substring that matches a specified regular expression from a target string.

    Syntax: regexp_extract(expr, regularExpr)

  • Extracts and returns the nth substring that matches a specified regular expression from a target string.

    Syntax: regexp_extract(expr, regularExpr, n)

Table 2 Parameter description

Parameter

Description

Type

Mandatory

expr

Target string.

String

Yes

regularExpr

Regular expression containing capture groups. (\d)(\d) indicates two capture groups.

String

Yes

n

nth substring that matches the regular expression.

Integer

No

Return value type: string

Example: SELECT REGEXP_EXTRACT('HTTP/2.0', '\d+')

Table 3 Query and analysis results

Type

Query Statement

Returned Result

Scenario 1

REGEXP_EXTRACT('HTTP/2.0', '\d+')

2

Scenario 2

REGEXP_EXTRACT ('HTTP/2.0', '\d+', 1)

2

regexp_like

This function checks whether a target string matches a specified regular expression.

Syntax: regexp_like(expr, regularExpr)

Table 4 Parameter description

Parameter

Description

Type

Mandatory

expr

Target string.

String

Yes

regularExpr

Regular expression containing capture groups. (\d)(\d) indicates two capture groups.

String

Yes

Return value type: Boolean

Example: SELECT REGEXP_LIKE('HTTP/2.0', '\d+')

Table 5 Query and analysis results

Type

Query Statement

Returned Result

Scenario

REGEXP_LIKE('HTTP/2.0', '\d+')

true

regexp_extract_all

This function extracts all substrings that match a specified regular expression from a target string.

Syntax: regexp_extract_all(expr, regularExpr)

Table 6 Parameter description

Parameter

Description

Type

Mandatory

expr

Target string.

String

Yes

regularExpr

Regular expression containing capture groups. (\d)(\d) indicates two capture groups.

String

Yes

Return value type: array

Example: SELECT REGEXP_EXTRACT_ALL('HTTP/2.0', '\d+')

Table 7 Query and analysis results

Type

Query Statement

Returned Result

Scenario

REGEXP_EXTRACT_ALL ('HTTP/2.0', '\d+')

["2","0"]

regexp_replace

This function removes or replaces all substrings that match a specified regular expression from a target string.

  • Removes substrings that match a specified regular expression from a string and returns the substrings that remain.

    Syntax: regexp_replace(expr, regularExpr)

  • Replaces substrings that match a specified regular expression in a string and returns the result string.

    Syntax: regexp_replace(expr, regularExpr, replaceStr)

Table 8 Parameter description

Parameter

Description

Type

Mandatory

expr

Target string.

String

Yes

regularExpr

Regular expression containing capture groups. (\d)(\d) indicates two capture groups.

String

Yes

replaceStr

Replacement string.

String

No

Return value type: string

Example: SELECT REGEXP_REPLACE('ab12cd34', '\d+'), REGEXP_REPLACE('ab12cd34', '\d+', '00')

Table 9 Query and analysis results

Type

Query Statement

Returned Result

Scenario 1

REGEXP_REPLACE('ab12cd34', '\d+')

abcd

Scenario 2

REGEXP_REPLACE('ab12cd34', '\d+', '00')

ab00cd00

regexp_split

This function splits a target string and returns the substrings after splitting.

Syntax: regexp_split(expr, regularExpr)

Table 10 Parameter description

Parameter

Description

Type

Mandatory

expr

Target string.

String

Yes

regularExpr

Regular expression containing capture groups. (\d)(\d) indicates two capture groups.

String

Yes

Return value type: array

Example: SELECT REGEXP_SPLIT('request_uri:/request/path-0/file-7','/')

Table 11 Query and analysis results

Type

Query Statement

Returned Result

Scenario

REGEXP_SPLIT('request_uri:/request/path-0/file-7','/')

["request_uri:","request","path-0","file-7"]