REGEXP_COUNT
Syntax
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
Start((START)) --> REGEXP_COUNT[REGEXP_COUNT]:::quoted
REGEXP_COUNT --> End((END))
Purpose
The REGEXP_COUNT SQL function counts how often a regular expression occurs in the given value. Returns 0 when the regular expression is not contained in the given value. The regular expression must follow the Microsoft.net regular expression language.
Occurrences do not overlap. The search for the next occurrence resumes after the end of the previous one, so aa occurs once in aaa and not twice.
See also REGEXP_INSTR, REGEXP_LIKE, REGEXP_REPLACE and REGEXP_SUBSTR.
Parameters:
- Input (
varchar2): The text to search through. - Pattern (
varchar2): Regular expression pattern. - Start position (optional,
int32): The start index from the input. Defaults to1. - Match_parameter (optional,
varchar2): A text literal that lets you change the default matching behaviour of the function. Defaults to''.
Returns: the number of occurrences of the pattern in the input, counted from the start position onwards, and empty when either the input or the pattern is empty.
The match is case-sensitive unless the match parameter says otherwise. When the match parameter holds both c and i, the last of the two decides, as in Oracle.
Examples
The following example counts the digits:
select regexp_count('2, 5, and 10 are numbers', '\d')
-------------------
4
The following example counts one occurrence rather than two, since occurrences do not overlap:
select regexp_count('aaa', 'aa')
-------------------
1