How To Use Regular Expressions(Regex) – In UiPath

Regular expressions are useful in extracting information from data such as log files, spreadsheets, databases e.t.c

We here are actually writing the pattern that will match our requirement and will be capable of helping us to analyze further.

They are widely used in almost all the programming languages like C#, Python, Java and many…

While performing automation, we might sometimes want to fetch the EMAILID, PHONE NUMBER or ZIP code from the data.

Let’s see how to do that!!!

Example

Implementation using UiPath :

Let us implement a workflow to extract EMAIL ID from a given text using Regular Expressions.

Major Steps That We Will Implement:

1. Check if the given text contains any email id?
2. Find all the matches
3. Extract user name from the email id.

Step 1:
Drag “Assign” activity into the designer panel and supply sample data to it.

i.e. “my email id is sharathkumarraju@gmail.com.”

How To Use Regular Expressions In UiPath 1

Step 2:
Drag “Is Match” activity into the designer panel to find if the sample data contains any email ids in it and supply the required parameters.

Note:
Regular expression for email id is : “([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})”

How To Use Regular Expressions In UiPath 2How To Use Regular Expressions In UiPath 3

Step 3:
Drag “IF” activity into the designer panel to check if we found any matches through the above activity

How To Use Regular Expressions In UiPath 4.PNG

Step 4:
Drag “Matches” activity into the designer panel to find all the email matches and supply the required parameters.

How To Use Regular Expressions In UiPath 5How To Use Regular Expressions In UiPath 6

Step 5:
Drag “Message Box” activity to display the first occurrence from the above-obtained result.

How To Use Regular Expressions In UiPath 7.PNG

Step 6:
Drag “Replace” activity to extract the username from the above-fetched email id and pass the mandatory fields

How To Use Regular Expressions In UiPath 8How To Use Regular Expressions In UiPath 9

Step 7:
Drag “Message Box” activity to display the extracted username.

How To Use Regular Expressions In UiPath 10.PNG

Step 8:
Finally, execute the workflow 🙂

 

Click here to download the Source Code…

Hope it has helped you… 

Confused about writing a REGULAR EXPRESSION?

Please find the below information to get you started 🙂

Different characters and their uses:

/s : matches any whitespace characters such as space and tab
/S : matches any non-whitespace characters
/d : matches any digit character
/D : matches any non-digit characters
/w : matches any word character (basically alpha-numeric)
/W : matches any non-word character
/b : matches any word boundary (this would include commas, spaces, semi-colons, etc)

Asterisk(*) can be used to match zero or more characters
ex : shara* will match shara,sharat and sharath…

Plus(+) can be used to match a repating character
ex: shara+ will match shara,sharaa and sharaaaa…

Curly braces{…} can be used to match a repeating character word with min and max count
ex: shara{1,3}th will match sharath,sharaaath and sharaaaath

Caret(^): can be used to match a string that begins with a particular pattern
Example : ^\ra will match with patterns like raju,raaj,ra e.t.c

dollar( $ ): can be used to match a string that ends with a particular pattern
Example : -\111$ will match with patterns like 111, 123111, abc111 e.t.c

Advertisements

Author: Sharath Raju

Founder@www.ExcelCult.com

Leave a Reply