tencent cloud

Cloud Log Service

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Features
Available Regions
Limits
Concepts
Service Regions and Service Providers
Purchase Guide
Billing Overview
Product Pricing
Pay-as-You-Go
Billing
Cleaning up CLS resources
Cost Optimization
FAQs
Getting Started
Getting Started in 1 Minute
Getting Started Guide
Quickly Trying out CLS with Demo
Operation Guide
Resource Management
Permission Management
Log Collection
Metric Collection
Log Storage
Metric Storage
Search and Analysis (Log Topic)
Search and Analysis (Metric Topic)
Dashboard
Data Processing documents
Shipping and Consumption
Monitoring Alarm
Cloud Insight
Independent DataSight console
Historical Documentation
Practical Tutorial
Log Collection
Search and Analysis
Dashboard
Monitoring Alarm
Shipping and Consumption
Cost Optimization
Developer Guide
Embedding CLS Console
CLS Connection to Grafana
API Documentation
History
Introduction
API Category
Making API Requests
Topic Management APIs
Log Set Management APIs
Index APIs
Topic Partition APIs
Machine Group APIs
Collection Configuration APIs
Log APIs
Metric APIs
Alarm Policy APIs
Data Processing APIs
Kafka Protocol Consumption APIs
CKafka Shipping Task APIs
Kafka Data Subscription APIs
COS Shipping Task APIs
SCF Delivery Task APIs
Scheduled SQL Analysis APIs
COS Data Import Task APIs
Data Types
Error Codes
FAQs
Health Check
Collection
Log Search
Others
CLS Service Level Agreement
CLS Policy
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Regular Expression Function

PDF
Focus Mode
Font Size
Last updated: 2024-01-22 10:52:48
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(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(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(x, regular expression)
Checks whether a specified string matches a specified regular expression.
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(x, regular expression)
Splits a specified string into multiple substrings by using a specified regular expression and returns a collection of the substrings.


regexp_extract_all

The regexp_extract_all function is used to extract the substrings that match a specified regular expression from a specified string.

Syntax

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

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

Array

Example

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
[1,1]

regexp_extract

The regexp_extract function is used to extract the first substring that matches a specified regular expression from a specified string.

Syntax

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

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_all(http_protocol, '\\d+')
Query and analysis result
1

Example 2. Extract the file information from the value of the request_uri field and count the number of times each file is accessed

Query and analysis statement
* | select regexp_like(server_protocol, '\\d+')
Query and analysis result

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

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