How to Use UiPath RegEx: 3 Best Methods For Data Extraction

In this Tutorial, you will be learning UiPath Regex which is a short name for Regular Expression. UiPath supports the use of regex, so before using this you should know what is about and on which use case you can use this in your automation process.

Here in this blog, we have included a complete guide on RegEx in UiPath Studio. After learning the use of RegEx in UiPath studio, you will feel it is worthwhile to improve your UiPath Automation. So don’t wait let’s go through it.

Introduction

In this article, we will be discussing using regex to extract data in UiPath. We’ll provide you with a detailed step-by-step guide that will make it simple for you to use regular expressions(RegEx) in UiPath Studio to extract data. You may extract particular information from various forms of text with the use of regular expressions.

A. What is UiPath RegEx?

Regular Expression also known as RegEx is a special sequence of characters or strings used to search patterns in UiPath Studio. UiPath developers can use this feature to extract data from various forms such as email, pdf, etc.

RegEx in UiPath can be used to Replace, Match, and Extract specific information for a huge amount of string. So manually it is very difficult to extract specific data or values from a bulk of data. RegEx can also be used for searching, data validation, and text processing.

RegEx also helps you to identify multiple UI Elements with a single search. It also supports various other programming languages. To test your regular expression you can use regex101. You can also use the UiPath Regex builder to build regular expressions based on your needs.

B. Importance of UiPath RegEx in automation

Using Regular Expression in your automation process is important as helps UiPath Developers to extract data much easier than any other method.

Since regular expression helps to get specific data from a large text, it can reduce the time consumption in your process.

If you are using an older method or not using regular expression in your process then you have to include multiple activities to process the required data from a large text which can increase your process time and memory. Also, its complexity can increase.

C. Syntax and Usage of Regular Expression (RegEx) in UiPath Studio

UiPath Regular Expression

A simple regular expression can have the following elements.

ElementsDescription
CharactersCharacters are sequences of alphabets. Eg: the regular expression “RPA” matches the exact string “RPA”.
WildcardsAsterisk (“*”) can be used to match characters or string 
Character classesA group of characters that can match a single character is defined using square brackets. Eg: regular expression “[aeiou]” matches any vowel
AlternationOne of several potential strings can be matched using the “|” (vertical bar) character. The regular phrase “bus|car,” for instance, matches either “bus” or “car.”
Anchors“^” (caret) and “$” (dollar sign) can also be used to match string
Quantifiers“+” (plus sign) and “?” (question mark)

How Does Regex Search Work?

It acts as a UiPath Regex Selector. The element’s tag must have a matching option as shown below to make advantage of the RegEx search capabilities:

OptionDescription
matching:<tag_name>=’regex’It enables you to define the target search tag, which is decided by the value of <tag name>.
<tag_name>='<regex_command>'uses the <regex command> expression to identify the <tag name> and enables you to set the search pattern.

The following selection types now allow RegEx UiPath Selector:

Selector TypeSupport
<wnd>✔️
<html>✔️
<webctrl>✔️
<java>✔️
<ctrl>✔️
<sap>✔️
labels that can be used to identify a process. Eg: <html app="firefox.exe">
Regular ExpressionDescriptionReturned Results
(.*ABC.*)|(.*Sample Free Automation*)It Matches every specific string that contains the ABC or Sample Free Automation strings. (…) leading ABC tool (…)
 UiPath is a Sample Free Automation (…)
^Index[0-5]It Matches every specific string starting with the Index value, followed by any integer number between 0 and 5. Index5
 Index03

How to Extract data using UIPath regex

To extract data using regex or UiPath Regex extractor in uipath studio you can use any one of the below methods.

1. Using Maches Activity in UiPath Studio

One of the ways to extract data in UiPath studio using regular expression is with the help of regex uipath matches activity. You can follow the below steps to implement them on your workflow.

Here we have created a pdf file with name “RPA Tutorials Invoice.pdf” and added “Invoice Number 12345-6789” into the pdf file.

  1. Open UiPah Studio and Create a new process
  2. Drag and drop “Read PDF Text Activity” and select the pdf file path.
  3. Drag and drop “Maches Activity” and add the below values to its properties section.
Input: str_invoice
Pattern: "(?<=Invoice Number ).*"
RegexOption: IgnoreCase, Compiled
Result: ienMaches
  1. Now add “Write Line” to your workflow and add the below values to its text box.
ienMaches(0).value
UiPath Maches Activity
UiPath Maches Activity

variables used here are:

NameVariable TypeScopeDefault
str_invoiceStringRPA_TutorialEnter a VB Expression
ienMachesIEnumerable<match>RPA_TutorialEnter a VB Expression

The output of RegEx using Maches Activity

The output of UiPath RegEx Using Matches activity
The output of RegEx Using Matches activity

It has successfully detected and extracted Invoice Number 12345-6789 from the pdf file. Here we have used the UiPath Regex match to string method or regex uipath string method.

2. Using Assing Activity in UiPath Studio

Another way to implement is with the help of Regex UiPath assign activity.

Consider the text ” Total Amount due is $5000.00, please pay before 01/25/2024”. In this text, the format of the text can change but the total amount will not change. So here we want to extract the total amount and save it to string ie, 5000.00.

  1. Create a variable Str_Input. and add the text to its default value in double quotes
" Total Amount due is $5000.00, please pay before 01/25/2024"
  1. Drag and drop the assigned activity into your workflow and add the following values to it. Set variable as Str_Output.
System.Text.RegularExpressions.Regex.Match(Str_Input, "(?<=\$)(\d+,?)+(\.\d+)").Value
  1. Now add a “Write Line” activity and set the variable Str_Ouput to your text box. Now Regex UiPath activity has been completed.
UiPath RegEx using Assign Activity
RegEx using Assign Activity

The UiPath Regex replacement method can also be used with this matching activity.

Variables used in this method are:

NameVariable TypeScopeDefault
Str_OutputStringRPA_TutorialEnter a VB Expression
Str_InputStringRPA_Tutorial” Total Amount due is $5000.00, please pay before 01/25/2024″

The output of RegEx using Assign Activity

The output of RegEx using the Assign activity
The output of RegEx using the assign activity

In the above screenshot you can see 5000.00 value has been extracted from a sequence of characters Here we use the UiPath RegEx Match method.

3. Other Examples Use Case of Regular Expression in UiPath

We have explained the use case in detail you can use this knowledge to implement the following use cases.

Extract a phone number:

([0-9]( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})

Extract an email address:

((?>[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)

Extract a date:

(?:(?:(?:(?:0?[13578]|1[02])(?<first>\/|-|\.)31)\k<first>|(?:(?:0?[13-9]|1[0-2])(?<second>\/|-|\.)(?:29|30)\k<second>))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(?<third>\/|-|\.)29\k<third>(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(?<fourth>\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\k<fourth>(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:(?:(?:January|March|May|July|August|October|December)(?<fifth>\/|-|\s)31)\k<fifth>|(?:(?:January|March|April|May|June|July|August|September|October|November|December)(?<sixth>\/|-|\s)(?:29|30)\k<sixth>))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:February(?<seventh>\/|-|\s)29\k<seventh>(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:January|February|March|April|May|June|July|August|September|October|November|December)(?<eighth>\/|-|\s)(?:0?[1-9]|1\d|2[0-8])\k<eighth>(?:(?:1[6-9]|[2-9]\d)?\d{2}))

Extract a URL:

(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-a-zA-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-a-zA-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-a-zA-Z0-9+&@#\/%=~_|$?!:,.]*\)|[a-zA-Z0-9+&@#\/%=~_|$])

Extract a time in hh:mm: ss Format:

\d{2}:\d{2}:\d{2}

Extract a zip code:

\d{5}

Extract a dollar amount:

\$\d{1,3}(,\d{3})*(\.\d{2})?

Extract a credit card number:

\d{4}-\d{4}-\d{4}-\d{4}

Extract a street address:

\d+\s+[a-zA-Z]+\s+[a-zA-Z]{2,}

Conclusion

Till now we have gone through a Regex UiPath Tutorial in detail. So now you have learned how to use the regular expression on your uipath studio. you can use this method on various use cases for data extraction from a large text.

This blog can be used as a UiPath RegEx documentation as we have cleared all the necessary things you need to understand about regular expression in uipath studio. This method is one of the good methods as its extracted data can be more accurate compared to other methods.

Faq on RegEx UiPath

  1. How to use regex with UiPath?

    To use regex with uipath you can use Maches activity in uipath studio. It provides a regular expression configuration window, in which you can add your custom regular expressions

  2. How to extract only numbers from a string in UiPath?

    To extract only numbers from a string in uipath you can use the regular expression “System.Text.RegularExpressions.Regex.Match(Str_Input, "(?<=\$)(\d+,?)+(\.\d+)"). Value“. Here Str_Input is the variable that stores the string in which you want to extract a number.

  3. How to use regex match in UiPath?

    To use RegEx match in UiPath you can use either the assign activity or the Maches activity. Matches activity provides a regex configuration wizard in which you can create your regular expression.

  4. How to split using regex in UiPath?

    To use UiPath Regex split you can use matches activity. To split a string separated by a comma use can use Input as yourStringVariable and pattern as “,\s*”. If you provide strings a,b, and c then it will give a string without commas. since the string separated by the coma has been split.

  5. What is regex builder in UiPath?

    The Regex Builder is a tool in UiPath Studio that allows you to easily create regular expressions (regex) by visually selecting the desired elements and building the pattern step by step.

  6. How to replace using regex match in UIPath

    To replace using regex match in uipath you can use regex. replace method in an assigned activity.

Leave a Reply

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