activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

用户界面自动化活动

上次更新日期 2026年2月28日

正则表达式搜索

正则表达式 (RegEx) 是一种特殊的文本字符串,用于描述搜索模式。这使其极适用于搜索、文本处理和数据验证。在选取器中使用正则表达式搜索功能后,仅执行一次搜索即可识别多个目标元素。如不使用正则表达式,则需构建多个选取器来识别各个目标元素。

正则表达式搜索的工作方式

为了使用正则表达式搜索功能,您需在要识别的元素的标签中加入一个匹配选项,如下所示:

选项描述
matching:<tag_name>=’regex’用于指定目标搜索标签,具体取决于 <tag_name> 值。
<tag_name>='<regex_command>'允许您通过用于识别 <tag_name><regex_command> 表达式指定搜索模式。

支持的选取器类型

以下选取器类型目前均支持正则表达式搜索:

选取器类型支持
<wnd>
<html>
<webctrl>
<java>
<ctrl>
<uia>
<sap>
标识流程名称的标签。 示例:<html app="firefox.exe">

假设我们要针对计算器应用程序创建自动化流程。但为达到本示例目的,<name> 标签的值需在 0 到 2 之间进行调整。如不使用正则表达式搜索,则需构建两个选取器,每个选取器各对应于 <name> 标签的每个值,如下所示:

<name='Display is 0'> 标签选取器

<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' />  <uia cls='LandmarkTarget' />  <uia automationid='CalculatorResults' name='Display is 0' role='text' />
<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' />  <uia cls='LandmarkTarget' />  <uia automationid='CalculatorResults' name='Display is 0' role='text' />

<name='Display is 2'> 标签选取器

<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' />  <uia cls='LandmarkTarget' />  <uia automationid='CalculatorResults' name='Display is 2' role='text' />
<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' />  <uia cls='LandmarkTarget' />  <uia automationid='CalculatorResults' name='Display is 2' role='text' />

在第二个 <uia> 标签中引入正则表达式搜索后,系统将会生成一个可与以上两种情况相匹配的选取器。本示例中的有效选取器大致类似于这样:

<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' /> 
<uia cls='LandmarkTarget' /> 
<uia automationid='CalculatorResults' name='Display is \d' role='text' matching:name='regex' />
<wnd app='applicationframehost.exe' appid='Microsoft.WindowsCalculator_8wekyb3d8bbwe!App' title='Calculator' /> 
<uia cls='LandmarkTarget' /> 
<uia automationid='CalculatorResults' name='Display is \d' role='text' matching:name='regex' />

matching:name='regex' 属性指示选取器使用正则表达式识别 <name> 标签,而 <name='Display is \d'> 命令则会返回所识别 <name> 标签的所有数值。

有关正则表达式搜索的工作方式及其返回值的几个附加示例如下:

正则表达式

描述

返回的结果

(.*RPA.*)|(.*Robotic Process Automation*)

匹配包含 RPA机器人流程自动化字符串的所有字符串。

  • (...) leading RPA tool (...)
  • UiPath is a Robotic Process Automation (...)

^Index[0-5]

匹配以 Index 值开头、后跟 0 到 5 之间任意数字的所有字符串。
  • Index5
  • Index03

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新