Regular Expression Functions
This section describes regular expression functions, including their syntax, parameters, and usage examples.
Function List
| Function | Description |
|---|---|
| Extracts a substring that matches a specified regular expression from a target string. | |
| Checks whether a target string matches a specified regular expression. | |
| Extracts all substrings that match a specified regular expression from a target string. | |
| Removes or replaces all substring that match a specified regular expression from a target string. | |
| 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.
- Extracts and returns the nth substring that matches a specified regular expression from a target string.
Syntax: regexp_extract(expr, regularExpr, n)
| 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+')
| 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)
| 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+')
| 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)
| 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+')
| 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.
- Replaces substrings that match a specified regular expression in a string and returns the result string.
| 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')
| 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)
| 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','/')
| Type | Query Statement | Returned Result |
|---|---|---|
| Scenario | REGEXP_SPLIT('request_uri:/request/path-0/file-7','/') | ["request_uri:","request","path-0","file-7"] |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.