正規表現検索について
正規表現は、検索パターンを記述するための特別なテキスト文字列です。このため、検索、テキスト処理、データ検証に最適です。セレクターで正規表現検索機能を使用すると、1 回の検索実行で複数のターゲット要素を特定できます。正規表現がない場合は、各ターゲット要素を特定するために複数のセレクターを作成する必要がありました。
正規表現検索の仕組み
正規表現検索機能を使用するには、次のように、特定する要素のタグに一致オプションを含める必要があります。
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> | ![]() |
<html> | ![]() |
<webctrl> | ![]() |
<java> | ![]() |
<ctrl> | ![]() |
<sap> | ![]() |
<silverlight> | ![]() |
Tags which identify a process name. Example: <html app="firefox.exe"> | ![]() |
正規表現検索の使用例
Calculator アプリケーションをターゲットとするオートメーション プロセスを作成するとします。ただし、この例の目的のために、<name>
タグの値は 0〜2 の間で変化します。正規表現検索がない場合は、次のように、<name>
タグの各値に 1 つずつ、2 つのセレクターが作成されます。
<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' />
2 番目の <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' />
matching:name='regex'
属性は、正規表現を使用して <name>
タグを特定するようセレクターに指示し、<name='Display is \d'>
コマンドは、特定する <name>
タグのすべての数値を返します。
以下は、正規表現検索の仕組みと、どのような値が返されるかを示すいくつかの例です。
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 年前に更新