- Categories:
REGEXP_COUNT¶
Returns the number of times that a pattern occurs in a string.
Syntax¶
Arguments¶
Required:
subjectThe string to search for matches.
patternPattern to match.
For guidelines on specifying patterns, see String functions (regular expressions).
Optional:
positionNumber of characters from the beginning of the string where the function starts searching for matches. The value must be a positive integer.
Default:
1(the search for a match starts at the first character on the left)parametersString of one or more characters that specifies the parameters used for searching for matches. Supported values:
Parameter
Description
cCase-sensitive matching
iCase-insensitive matching
mMulti-line mode
eExtract submatches
sSingle-line mode POSIX wildcard character
.matches\nDefault:
cFor more information, see Specifying the parameters for the regular expression.
Returns¶
Returns a value of type NUMBER. Returns NULL if any argument is NULL.
Usage notes¶
See the General usage notes for regular expression functions.
Collation details¶
Arguments with collation specifications currently aren’t supported.
Examples¶
The following example counts occurrences of the word was. You can use the \b metacharacter to indicate
a word boundary. In the following example, matching begins at the first character in the string w and
ends at the last character in the string s, and so doesn’t match words that contain the string (such
as washing):
The following example uses the i parameter for case-insensitive matching of the character e:
The following example illustrates overlapping occurrences. Create a table and insert data:
Run a query that uses REGEXP_COUNT to count the number of times that the following pattern is found in each row: a punctuation mark followed by digits and letters, followed by a punctuation mark.
The remaining examples use the data in the following table:
The following query returns the total number of messages for each day by searching for the delimiter (,) and
adding one to the total:
Assume that errors always begin with ER followed by a hyphen and a four-digit number. The following
query counts the number of errors for each day: