订阅

UiPath Studio

UiPath Studio 指南

正则表达式搜索

关于正则表达式搜索

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

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

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

Option

Description

matching:<tag_name>=’regex’

Allows you to specify the target search tag, determined by the <tag_name> value.

<tag_name>='<regex_command>'

Allows you to specify the search pattern through the <regex_command> expression used to identify the <tag_name>.

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

Selector Type

Support

<wnd>

check_markcheck_mark

<html>

check_markcheck_mark

<webctrl>

check_markcheck_mark

<java>

check_markcheck_mark

<ctrl>

check_markcheck_mark

<sap>

check_markcheck_mark

Tags which identify a process name.
Example: <html app="firefox.exe">

no_rightno_right

正则表达式搜索使用示例

Let's assume that we want to create an automation process which targets the Calculator application. However, for the purpose of this example, the value of the <name> tag alters between 0 and 2. Without the RegEx search, two selectors would have been built, one for each value of the <name> tag, as follows:

<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 2' role='text' />

Introducing RegEx search inside the second <uia> tag makes it possible to generate a single selector to match both cases. A valid selector, in this case, looks something like this:

<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' />

The matching:name='regex' attribute instructs our selector to use RegEx to identify the <name> tag, while the <name='Display is \d'> command returns all the numerical values for the <name> tag it identifies.

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

Regular Expression

Description

Returned Results

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

Matches every string containing the RPA or Robotic Process Automation strings.

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

^Index[0-5]

Matches every string starting with the Index value, followed by any number between 0 and 5.

Index5
Index03

2 年前更新

正则表达式搜索


建议的编辑仅限用于 API 参考页面

您只能建议对 Markdown 正文内容进行编辑,而不能建议对 API 规范进行编辑。