Using the build in activities ‘Matches’ and ‘Is Match’ is often useful, however there is a much more simple solution (at least for a lot of cases) to extract data out of text with RegEx in UiPath.

Consider the following text: “Amout due $2,000.00, please pay before 04/24/2020”, where the format always will be the same, but the amount will change. We want to extract the amount and store it in a string, i.e. “2,000.00”.

Fig. 1: Entire workflow that extracts the amout from the input string ‘strInput’.

Assign Variables

First assign the two variables in the variables manager:

  • ‘strInput’, a string where we store our input
  • ‘strOutut, a string to hold the value of the extracted amount

Use RegEx to assign a value to our output string, ‘strOutput’

Fig. 2: Drag in an ‘Assign’ activity
Fig. 3: Fill in the ‘Assign’ on left and right side

Drag in an ‘Assign’ activity (Fig. 2) and set the left side to ‘strInput’ and the right side to ‘System.Text.RegularExpressions.Regex.Match(strInput, “(?<=\$)(\d+,?)+(\.\d+)”).Value’ (Fig. 3).

Lets dig into the expression on the right side:

  • System.Text.RegularExpressions is the Microsoft .NET namespace
  • Regex.Match is the method (covered here https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.match?view=netframework-4.8)
  • strInput is the string to search in
  • “(?<=\$)(\d+,?)+(.\d+)” is the RegEx pattern, we use to extract the amount
    • (?<=\$) is a postive lookbehind, where we specify, we want to look behind a ‘$’
    • (\d+,?) then we look for one or more digits (\d+) and one or none thousand delimiter
    • + one or more of the preceeding patters (otherwise it would stop after ‘2,’
    • (\.\d+) a decimal delimiter (\.) and one or more digits (\d+)

Write the output out

Fig. 4: Write Line

Now just drag in a ‘Write Line’ and set the value to our Output Variable, ‘strOutput’

And our result is…

Fig. 5: Our extracted value

And then we’re done (Fig. 5). The workflow will also work with all other values.

Additional Regex material

I’ve created this video tutorial about RegEx, if you want further informations:

Anders Jensen

RPA DEVELOPER & YOUTUBER

Anders Jensen is the RPA Lead at Lessor A/S (Part of Paychex Inc) and an advanced certified UiPath RPA Instructor.

Using his extensive experience in automating interfaces such as Windows, SAP and browsers Anders develops enterprise RPA solutions automating work for customers and collegues one task at a time.

In the evenings and weekends Anders is passionate about teaching others RPA by making instructional videos on his YouTube channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

Anders Jensen

RPA DEVELOPER & YOUTUBER

Anders Jensen is the RPA Lead at Lessor A/S (Part of Paychex Inc) and an advanced certified UiPath RPA Instructor.

Using his extensive experience in automating interfaces such as Windows, SAP and browsers Anders develops enterprise RPA solutions automating work for customers and collegues one task at a time.

In the evenings and weekends Anders is passionate about teaching others RPA by making instructional videos on his YouTube channel.