The example below explains how to find and matche the values corresponding to a defined regular expression and replaces them with a specified value. This example uses activities such as the Matches and Replace. You can find them in the UiPath.System.Activities package.
This is how the automation process can be built:
- Open Studio and create a new Process.
- Drag a Sequence container in the Workflow Designer.
- Create the following variables:
Variable Name | Variable Type | Default Value |
---|---|---|
| String | "I have 10.5 RON in first account and 25 RON in second account!" |
| IEnumerable | |
| String |
- Drag a Matches activity inside the Sequence container.
- In the Properties panel, add the variable
StringToAnalyze
in the Input field. - Select the
IgnoreCase
andCompiled
options from the RegexOption drop-down list. - Add the variable
AccountMatches
in the Result field.
- In the Properties panel, add the variable
- Click the Configure Regular Expression button.
- Select the Advanced option from the RegEx drop-down list.
- Add the expression
([0-9]+\.*[0-9]* RON)
in the Value field. - Select the Exactly option from the Quantifiers drop-down list.
- Select the check box for the IgnoreCase option.
- Click the Save button.
Note:
For more information about how to set up a RegEx Expression, please visit this page.
- Drag a ForEach activity underneath the Matches activity.
- In the Properties panel, select the System.Text.RegularExpressions.Match option from the TypeArgument drop-down list.
- Add the variable
AccountMatches
in the Values field.
- Place a Log Message activity inside the ForEach activity.
- Select the option Info from the Level drop-down list.
- Add the expression
account.ToString
in the Message field.
- Drag a Replace activity below the ForEach activity.
- In the Properties panel, add the variable
StringToAnalyze
in the Input field. - Add the value
IgnoreCase, Compiled
in the RegexOption field. - Add the expression
"$2 $1"
in the Replacement field. - Add the variable
FinalString
in the Result field.
- In the Properties panel, add the variable
- Click the Configure Regular Expression button.
- Select the Advanced option from the RegEx drop-down list.
- Add the expression
([0-9]+\.*[0-9]* RON)
in the Value field. - Select the Exactly option from the Quantifiers drop-down list.
- Select the check box for the IgnoreCase option.
- Click the Save button.
- Place a Log Message activity inside the ForEach activity.
- Select the option Info from the Level drop-down list.
- Add the variable
FinalString
in the Message field.
- Run the process. The robot finds and matches the values corresponding to the defined regular expression and replaces them with the specified value.
- This is how your workflow should look:


Updated 9 months ago