Communications Mining
最新
False
Communications Mining 用户指南
Last updated 2024年7月2日

Building custom regex general fields

所需权限:“修改数据集”。

What are Custom Regex General Fields?

A Custom Regex General Field can be used to extract and format spans of text that have a known repetitive structure, such as IDs or reference numbers.

This is a useful option for simple, structured general fields with little variation, whereas for those with significant variation and where context has a big influence on predictions, a machine-learning based general field would be the right choice. Combinations of the two can be used in any dataset within Communications Mining.

A broader Regex (i.e. set of rules to define the general field) can also be used as the base of a custom general field. This combines the rules with contextual, machine learning based refinement through training within Communications Mining to create sophisticated custom general fields. This provides the most optimal performance as well as the necessary restrictions on values extracted for automation.

自定义正则表达式模板

A Custom Regex General Field is made up of one or more Custom Regex Templates. Each template expresses one way to extract (and format) the general field.

Combined together, these templates offer a flexible and powerful way to cover multiple representations of the same general field type.

模板由两部分组成:

  1. The regex (regular expression), which describes the constraints that need to be met by a span of text to be extracted as a general field
  2. 格式,表示如何将提取的字符串规范化为更标准的格式

例如,如果您的客户 ID 可以是单词“ID”后跟 7 位数字,也可以是包含 9 个字符的字母数字字符串,则两个模板将如下所示:



预先输入验证

在“正则表达式”或“格式”的文本框中键入内容时,界面将提供有关输入有效性的即时反馈。 例如,无效的输入正则表达式ID\ d{}将显示:

提取内容预览

The Custom Regex Template can be tested on text to ensure that it behaves as expected. Any general field that would be extracted with the Template will be shown in a list, with its value, as well as the position of the start and end characters.

例如,如果正则表达式为\d{4}且格式为ID-{$} ,则以下测试字符串将显示一次提取:


正则表达式

The regex is the pattern used to extract general fields in the text. See here for the syntax documentation.

命名捕获组可用于标识所提取字符串的特定部分,以便进行后续格式化。 捕获组的名称在所有模板中均应唯一,并且应仅包含小写字母或数字。

Formatting

Formatting can be provided to post-process the extracted general field.

默认情况下,不应用任何格式,平台返回的字符串将是正则表达式提取的字符串。 但是,如果需要,可以使用以下规则定义更复杂的转换。

变量

正则表达式中定义的任何命名捕获组都可以在格式化逻辑中用作变量,并使用$符号作为前缀。 请注意, $符号本身表示完整的正则表达式匹配。
然后,可以在格式化字符串中使用变量,以将相应的提取范围插入到平台返回的值中;变量名称需要用{}大括号括起来。
例如,如果我们想提取七位数字作为 ID,并返回这七位数字并加上ID-前缀,则正则表达式和格式将为:


或者,使用命名捕获组:


Later on, if the platform is given the text: My identification number is 1234567, it will return one general field: My identification number is 1234567, it will return one general field: ID-1234567

字符串操作

可以使用原始字符串,并且可以使用&符号连接字符串。
正则表达式(?P<id1>\b\d{3}\b)|(?P<id2>\b\d{4}\b)
Formatting{$id1 & "-" & $id2}
文本第一个 ID 为 123,第二个 ID 为 4567
General Field returned by the platform123-4567

功能

某些函数也可以在格式化中使用,以转换提取的字符串。 函数名称及其签名受 Excel 启发。

上部

将提取的范围中的所有字符转换为大写:

正则表达式\w{3}
Formatting{upper($)}
文本abc
General Field returned by the platformABC

降低

将提取的范围中的所有字符转换为小写:

正则表达式\w{3}
Formatting{lower($)}
文本AbC
General Field returned by the platformabc

属性

将提取的跨度大写:

正则表达式\w+\s\w+
Formatting{proper($)}
文本阿尔伯特·爱因斯坦
General Field returned by the platform阿尔伯特·爱因因

填充

使用给定字符将提取的范围填充至给定大小。

函数参数:

  1. 包含要填充的字符的文本
  2. 填充字符串的大小
  3. 用于填充的字符
正则表达式\d{2,5}
Formatting{pad($, 5, "0")}
文本123
General Field returned by the platform00123

替换

将某个字符替换为其他字符。

函数参数:

  1. 包含要替换的字符的文本
  2. 要替换的字符
  3. 旧字符应替换成的内容
正则表达式ab
Formatting{substitute($, "a", "12")}
文本ab
General Field returned by the platform12b

左侧

返回范围中的前 n 个字符。

函数参数:

  1. 包含要提取的字符的文本
  2. 要返回的字符数
正则表达式\w{4}
Formatting{left($, 2)}
文本ABCD
General Field returned by the platformAB

右侧

返回范围中的最后 n 个字符。

函数参数:

  1. 包含要提取的字符的文本
  2. 要返回的字符数
正则表达式\w{4}
Formatting{right($, 2)}
文本ABCD
General Field returned by the platformCD

返回范围中指定位置之后的 n 个字符。

函数参数:

  1. 包含要提取的字符的文本
  2. 要返回的第一个字符的位置
  3. 要返回的字符数
正则表达式\w{5}
Formatting{mid($, 2, 3)}
文本ABCDE
General Field returned by the platformBCD

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.