From 6a93e487c6e08de2180b76e6a68b07cf8b1db20e Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Mon, 21 Dec 2020 22:30:37 +0300 Subject: [PATCH] Document the countMatches function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Задокументировал функцию countMatches. --- .../functions/string-search-functions.md | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/en/sql-reference/functions/string-search-functions.md b/docs/en/sql-reference/functions/string-search-functions.md index 3cde7dd71d4..957866faea3 100644 --- a/docs/en/sql-reference/functions/string-search-functions.md +++ b/docs/en/sql-reference/functions/string-search-functions.md @@ -400,7 +400,8 @@ Result: └──────────────────────────────────────────────────────────────────────────────────────────┘ ``` -**See also** +**See Also** + - [extractAllGroupsVertical](#extractallgroups-vertical) ## extractAllGroupsVertical {#extractallgroups-vertical} @@ -440,7 +441,8 @@ Result: └────────────────────────────────────────────────────────────────────────────────────────┘ ``` -**See also** +**See Also** + - [extractAllGroupsHorizontal](#extractallgroups-horizontal) ## like(haystack, pattern), haystack LIKE pattern operator {#function-like} @@ -590,8 +592,55 @@ Result: └───────────────────────────────┘ ``` -[Original article](https://clickhouse.tech/docs/en/query_language/functions/string_search_functions/) - ## countMatches(haystack, pattern) {#countmatcheshaystack-pattern} Returns the number of regular expression matches for a `pattern` in a `haystack`. + +**Syntax** + +``` sql +countMatches(haystack, pattern) +``` + +**Parameters** + +- `haystack` — The string to search in. [String](../../sql-reference/syntax.md#syntax-string-literal). +- `pattern` — The regular expression with [re2 syntax](https://github.com/google/re2/wiki/Syntax). [String](../../sql-reference/data-types/string.md). + +**Returned value** + +- The number of matches. + +Type: [UInt64](../../sql-reference/data-types/int-uint.md). + +**Examples** + +Query: + +``` sql +SELECT countMatches('foobar.com', 'o') +``` + +Result: + +``` text +┌─countMatches('foobar.com', 'o')─┐ +│ 3 │ +└─────────────────────────────────┘ +``` + +Query: + +``` sql +SELECT countMatches('aaaa', 'aa') +``` + +Result: + +``` text +┌─countMatches('aaaa', 'aa')─┐ +│ 2 │ +└───────────────────────────────┘ +``` + +[Original article](https://clickhouse.tech/docs/en/query_language/functions/string_search_functions/)