diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_extract.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_extract.md new file mode 100644 index 0000000000..8cbf690eea --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_extract.md @@ -0,0 +1,27 @@ +# regexp_extract + +## Syntax + +`VARCHAR regexp_extract(VARCHAR str, VARCHAR pattern, int pos)` + +## Description + +对字符串 str 进行正则匹配,抽取符合 pattern 的第 pos 个匹配部分。需要 pattern 完全匹配 str 中的某部分,这样才能返回 pattern 部分中需匹配部分。如果没有匹配,返回空字符串。 + +## Examples + +``` +mysql> SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 1); ++-------------------------------------------------------------+ +| regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 1) | ++-------------------------------------------------------------+ +| b | ++-------------------------------------------------------------+ + +mysql> SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 2); ++-------------------------------------------------------------+ +| regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 2) | ++-------------------------------------------------------------+ +| d | ++-------------------------------------------------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_replace.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_replace.md new file mode 100644 index 0000000000..c131996cdc --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/regexp_replace.md @@ -0,0 +1,27 @@ +# regexp_replace + +## Syntax + +`VARCHAR regexp_replace(VARCHAR str, VARCHAR pattern, VARCHAR repl) + +## Description + +对字符串 str 进行正则匹配, 将命中 pattern 的部分使用 repl 来进行替换 + +## Examples + +``` +mysql> SELECT regexp_replace('a b c', " ", "-"); ++-----------------------------------+ +| regexp_replace('a b c', ' ', '-') | ++-----------------------------------+ +| a-b-c | ++-----------------------------------+ + +mysql> SELECT regexp_replace('a b c','(b)','<\\1>'); ++----------------------------------------+ +| regexp_replace('a b c', '(b)', '<\1>') | ++----------------------------------------+ +| a c | ++----------------------------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/repeat.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/repeat.md new file mode 100644 index 0000000000..4ef1eeb2f7 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/repeat.md @@ -0,0 +1,27 @@ +# repeat + +## Syntax + +`VARCHAR repeat(VARCHAR str, INT count) + +## Description + +将字符串 str 重复 count 次输出,count 小于1时返回空串,str,count 任一为NULL时,返回 NULL + +## Examples + +``` +mysql> SELECT repeat("a", 3); ++----------------+ +| repeat('a', 3) | ++----------------+ +| aaa | ++----------------+ + +mysql> SELECT repeat("a", -1); ++-----------------+ +| repeat('a', -1) | ++-----------------+ +| | ++-----------------+ +```