regexp_substr1
Calculates the substring in source that matches the specified pattern for the occurrence-th time, starting from the start_position.
Syntax
regexp_substr1(string <source>, string <pattern>[, bigint <start_position>[, bigint <occurrence>]])
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| source | Yes | STRING | The string to be searched. |
| pattern | Yes | STRING | The regular expression. The pattern to be matched. An error is returned if pattern is an empty string. |
| start_position | No | BIGINT | The starting position. Must be greater than 0. When not specified, the default is 1, meaning the match starts from the first character of source. |
| occurrence | No | BIGINT | The occurrence count. Must be greater than 0. When not specified, the default is 1, meaning the first matching substring is returned. |
Return Values
Returns a value of type STRING.
- If pattern is an empty string, an error is reported.
- If no match is found, NULL is returned.
- If start_position or occurrence is not of type BIGINT or is less than or equal to 0, an error is returned.
- If source, pattern, start_position, or occurrence is NULL, NULL is returned.
Example Code
Returns a.
select regexp_substr1('a1b2c3', '[a-z]'); Returns b.
select regexp_substr1('a1b2c3', '[a-z]', 2, 1); Returns c.
select regexp_substr1('a1b2c3', '[a-z]', 2, 2); Returns NULL.
select regexp_substr1('a1b2c3', null); What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot