你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

replace_regex()

将所有 正则表达式 匹配项替换为指定的模式。

弃用的别名:replace()

语法

replace_regex(source,lookup_regex,rewrite_pattern)

详细了解语法约定

参数

名称 类型 必需 描述
source string ✔️ 要搜索和替换的文本。
lookup_regex string ✔️ 要在 text 中搜索的正则表达式。 此表达式可将捕获组用括号括起来。
rewrite_pattern string ✔️ matchingRegex 执行的任何匹配的替换正则表达式。 使用 \0 引用整个匹配项,\1 用于第一个捕获组,\2 等用于后续捕获组。

返回

使用 rewrite_pattern 计算结果替换 lookup_regex 的所有匹配项后返回的 source。 匹配项不重叠。

示例

range x from 1 to 5 step 1
| extend str=strcat('Number is ', tostring(x))
| extend replaced=replace_regex(str, @'is (\d+)', @'was: \1')

输出

x str 替换的内容
1 数值为 1.000000 数值曾为:1.000000
2 数值为 2.000000 数值曾为:2.000000
3 数值为 3.000000 数值曾为:3.000000
4 数值为 4.000000 数值曾为:4.000000
5 数值为 5.000000 数值曾为:5.000000