UiPath Activities

The UiPath Activities Guide

Match and Replace

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:

  1. Open Studio and create a new Process.
  2. Drag a Sequence container in the Workflow Designer.
    • Create the following variables:
Variable Name
Variable Type
Default Value

StringToAnalyze

String

"I have 10.5 RON in first account and 25 RON in second account!"

AccountMatches

IEnumerable<Match>

FinalString

String

  1. Drag a Matches activity inside the Sequence container.
    • In the Properties panel, add the variable StringToAnalyze in the Input field.
    • Select the IgnoreCase and Compiled options from the RegexOption drop-down list.
    • Add the variable AccountMatches in the Result field.
  2. 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Run the process. The robot finds and matches the values corresponding to the defined regular expression and replaces them with the specified value.
  7. This is how your workflow should look:

Updated about a month ago


Match and Replace


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.