Matches activity to extract multiple url


I have to create a job where i need to get multiple URLs and sometimes we have 2 or sometime only 1.
So I want to know how to use Matches to extract URL even if only 1 URL is available.

Problem is if only 1 URL is available then its not working it need 2 URLs to work.
you can refer screenshot for better understanding of my problem.


Matches Condition:



Can you share few test url’s you are attempting to?



IF the matches is able to extract multiple URLs then

to extract those you can write as below

MatchesVariable(0).ToString, MatchesVariable(1).ToString

This will help you



The issue was due to hardcoding the index to get the each matched entry.

instead we can try like below. use for each loop to loop all the matched entries in our case all the URL’s so we can fetch one by one. Even we have one URL it will give you the result. Thanks.




Hi Srini,

thanks for the reply but the issue is when both URLS are available then it will work but if only 1st one is present and second one is missing then MatchesVariable(1).ToString is giving error saying object reference is not valid.
So i want a solution where we can take any of the URL.

Can you share your MATCH activity with conditions and property.


It is just sample workflow from my side. Could you pls share your sample string and your regex expression so that I will include my work flow and share it with you.

Mean while use your match activity and below create a for each loop and assign your match activity output in that and you can loop your matched entries in your case url’s instead of hard coding way so that if you get one url also you would not get any issue. Please refer the screenshots in the above post. Thanks.

i did as you showed in the screenshot but when we have 2 URLs then it is taking the second one not both.
for example below text will be used in MATCH activity where i want both highlighted URLS not the one.

<a href= class=“socialLinks__item” target=”_blank" rel=“noopener noreferrer”>linkedin<a href=Redirecting... class=“socialLinks__item” target=“_blank” rel=“noopener noreferrer”>facebook

Below is the regex editor screenshot:

Yeah it will take the url one by one in the loop and you can do your operations in the inside for each loop. If you want to print both the url you can use log message activity so that both url it will print in the output panel.

If you want to store the URLs in excel eg: if you have two URLs in the string you can store both the url in the Excel. For that you can use build data table activity in the beginning of your work flow create column like URL and use add data row activity to insert URL in the data table and out side for each loop use the write range activity to insert all the url in the Excel.

Please share us what you are trying to achieve so that we would happy to help you. Thanks.

1 Like


Thanks for the sample.

I have created two Regex Patterns both should work fine.
Pattern #1:

Regex pattern #2

Further to @kirankumar.mahanthi1’s post, here is a sample workflow. Main.xaml (12.0 KB)

Hopefully this helps you.

1 Like

Thanks for the reply and sample xml, but i want the output in a excel and the value of LinkedIn URL in Column A and Facebook in B column and if from both one is missing then it will give leave the row blank for the column.
I am also able to get the value in message box but unable to write in write range.
Please suggest?

I am using below if condition to take the URLs and if I use Message box to see if I am getting the result then yes it is showing the URL properly but not showing in excel.
Either i am getting all URLs in one column or in both columns the same value where Facebook and LinkedIn URL in same columns.



Keep write range activity out side your for each loop. Thanks


Take a look at this tutorial, start the video at 6:40. This video will show you how to convert your Regex Results into Excel.

How to extract data from PDF’s with RegEx in UiPath - Full Tutorial - YouTube

If I get a chance I will assist you but this tutorial should guide you through.

Edit: As per @kirankumar.mahanthi1’s post, you only want to write the range once. Not every time. So move it below the “For Each” activity.


Hi Bharat,

Finally understood your requirement. we have to use two build data tables one for first url pattern and second data table for second URL pattern.

use add data row to capture the first pattern url into first data table and for second pattern we have to store in the second data table and use for each loop to capture all the matches.

use two write range activity to insert the first pattern url’s nto A column and second pattern url’s into B column.

Attaching the sample work flow. i hope it helps your automation. thanks. (9.6 KB)