跳转至

RegexpExtract

概述

RegexpExtract 函数用于使用正则表达式从字符串中提取特定部分。

语法说明

RegexpExtract(<字符串>, <正则表达式>, <位置>)

参数说明

参数 必需 参数类型 说明
字符串 字段、表达式、常量 需要进行提取操作的字符串
正则表达式 字符串 用于匹配的正则表达式
位置 整数 提取的捕获组序号(从1开始)

示例

从产品描述中提取产品型号

假设在一个产品数据表中,产品描述存储在名为 ProductDescription 的字段中,格式为 "品牌 型号"。我们希望提取产品描述中的型号,可以使用如下表达式:

示例公式

RegexpExtract(ProductDescription, '(\w+)\s+(\w+)', 2)

数据示例

ProductID ProductDescription
P001 "Apple iPhone13"
P002 "Samsung GalaxyS21"
P003 "Google Pixel5"
P004 "Microsoft Surface7"
P005 "Sony PlayStation5"

计算结果

通过上述 RegexpExtract 函数表达式,结果将会是:

ProductID ProductDescription RegexpExtract
P001 "Apple iPhone13" "iPhone13"
P002 "Samsung GalaxyS21" "GalaxyS21"
P003 "Google Pixel5" "Pixel5"
P004 "Microsoft Surface7" "Surface7"
P005 "Sony PlayStation5" "PlayStation5"

RegexpExtract(ProductDescription, '(\w+)\s+(\w+)', 2) 使用正则表达式 (\w+)\s+(\w+) 匹配 ProductDescription 字段中的字符串,并提取第二个捕获组(即型号部分)。