Perception Session Variables and Regex in UiPath: A Broad overview
UiPath, which is a top robotic process automation (RPA) podium, enables developers to automate these tasks and integrate with broad applications. One of the most powerful features in UiPath is the performance to exploit data involving session variables and regular expressions (Regex). This blog post contributions insight into what session variables really mean in UiPath, as well as how to use them and how to apply regular expressions (Regex) to extract numbers even from strings.
What is a Session Variable in UiPath?
In UiPath, session variables are the lightweight data types that are used to store and move data between the components of a session, which is the life cycle of drilling down a business process.
A session is basically a process that is running in UiPath and can contain the required data for the automation while it is doing things like data extraction, application interaction, or sequence management.
Session variables are important in the automation of the processes where data have to be stored temporarily through several steps within the confines of a process. For sample, you may deposit user credentials, IDs or other vigorous data into a session variable for transmitting between activities or workflows.
How to Use Regex in UiPath: A Quick Overview
Regular expressions (Regex) are patterns that are applied to identify character combinations in strings In UiPath, Regex is pervasively operated for extracting, replacing, or corroborating texts according to the patterns.
The UiPath Regex package comes with AI-supported activities for Regex operations like Matches, Is Match, Replace, and Split.
UiPath Regex Package
UiPath must have Regex besides the Regex package (if it is not currently in your project). To do so:
- In UiPath Studio, use the Open Govern Packages window.
- Look for the UiPath.System.Activities package which encompasses Regex capability.
- Install or update

After the installation is finished, you can begin applying Regex-based activities in your workflows.
UiPath Regex Sample: Extracting Numbers from a String
One of the most typical applications of Regex in automation is to capture the identification of concrete patterns, like numbers, from text data. Authorize's show how you can get numbers from a string in the UiPath case.
Prototype:
Imagine a situation where we have an order number in a sentence, and aside from that, there are also some other texts. It is very likely that we will extract that number.
Exemplar string: Your order number is 12345 and it will be delivered soon
Your strategy to get the number (12345) from the text can be the following step in UiPath.
Step-by-Step Counselor:
- Assign Activity: Establish a new variable named inputString and use it to store the string. Set the value of the string to “Your order number is 12345 and it will be delivered soon.”.plaintextCopy codeinputString = Your order number is 12345 and it will be delivered soon.
- Regex Pattern: The pattern “\d+” is used in regex to match one or more digits in the string.plaintextCopy coderegexPattern = \d+ The pattern \d+ means match one or more digits.
- Matches Activity: In order to get digits use the Matches activity. Optionally, inputString can be the property to be set for the Input property and regexPattern for the Pattern property. The matched items should be stored in a MatchCollection variable, release's name it matches.
- Extract the First Match: The system first runs theMatchesactivity, and then the first match (if any) from thematchescollection can be retrieved. For illustration:plaintextCopy codeextractedNumber = matches(0).ToString
- Output: The variable extractedNumber will contain the extracted number (12345) since it was stored in this variable.
Complete UiPath Sequence: This will output how to Extract Numbers from String Employing Regex in UiPath
In the world of unstructured text data, you will often come across situations where you need to extract numbers that are buried inside the string. This is how you can do it successfully via UiPath's Regex tool:
- Pattern for Extracting Numbers: To identify any number use the regex\d+. This pattern identifies the sequences of digits existing in a string. Here is an exemplar of a pattern: Copy coderegexPattern = \d+
- Multiple Numbers: In case your string has got several numbers and you would like to extract all of them, you can cycle through theMatchCollectionoutputted by theMatchesactivity. For illustration, if your string isThe total price is 45 and discount is 5%, the regex pattern\d+would match45and5.Representation code:plaintextCopy codeFor Each match In matches Write Line: match.ToString
Practical Use Situations of Regex in UiPath: Here are some practical use events for Regex in UiPath:
- Extracting Dates: You are able to use Regex to extract dates from strings in different formats. For illustration, the pattern \d{2}/\d{2}/\d{4} might be a match with dates like 12/05/2023.
- Authenticating Email Locations: Regex is very helpful for corroborating email destinations. A regular pattern for email authentication is ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$.
- Text Cleaning: You can use Regex to get rid of the unneeded characters or formats from the strings. As an exemplar, use \s+ to substitute conjoined spaces with a unmarried one.
- Extracting IDs or Product Numbers: Use Regex to get the IDs that are hidden in the product descriptions, invoices, or order confirmations.
Closing
Comprehension of both session variables and regular expressions (Regex) is essential when automating tasks in UiPath Session variables help you to conduct and store data through many automation steps, whereas Regex is an progressive technique for string manipulation. Via developing the skills to use these tools, more expedient and forceful automation workflows can be produced.
In this navigator, we've grasped the simple issues, for illustration, how to extract numbers from strings exploiting Regex in UiPath and the useful UiPath Regex examples. The moment you is at home with the Regex patterns and the session variables, you will be seeing the ease in administering the intricate text administering and data extraction tasks inside your UiPath workflows.
Lucille
An effort offers a chance to learn, and a result provides valuable lessons.
