activities
latest
false
UiPath logo, featuring letters U and I in white

Workflow Activities

Last updated Dec 20, 2024

Match and Replace

The example below explains how to find and match the values corresponding to a defined regular expression and replaces them with a specified value. This example uses activities such as the Find Matching Patterns and Replace Matching Patterns. 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

       
  3. 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.
  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. Drag a ForEach activity underneath the Matches activity.

    • Inside the ForEach activity change the item to account.
    • 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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:



Here you can download an example.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.