RegEx Match for list of links

Hi, I have a bot that grabs links and saves them in a txt file.

What I want, is to check if the link already exists inside that txt, so it won’t get added again.
This is how the txt looks inside

https://domain.com/323971BEDD
https://domain.com/1AC9FB8BAD
https://domain.com/21036C5DD8
https://domain.com/2A121D9397
https://domain.com/143BF87C9F
https://domain.com/21BAD005DD
https://domain.com/21BAD005DD2

I made the next RegEx inside the page regexr.com
image_2022-06-07_182508893

image_2022-06-07_182520240

As you see, it is matching exactly what I need. The problem comes when I try to use that expression in UiPath.

The link that will save in the txt (and thus the one that I want to check) comes inside a string variable, and inside the variable the format is exactly this one
https:\/\/domain.com\/21BAD005DD(\n|$)
As you see, I’m scaping the “/” characters due to the RegEx Match.

This is the RegEx Match that I’m using

System.Text.RegularExpressions.Regex.Match(strTxt, strLinkToCheck).Success

The variable “strLinkToCheck” contains

https:\/\/domain.com\/21BAD005DD(\n|$)

The variable “strText” contains

https://domain.com/21BAD005DD
https://domain.com/21BAD005DD2

The problem is that it always returns false inside UiPath when I run it. Doesn’t matter if the link is inside the txt or not, it always returns false.

Can anyone help?. I’ll will appreciate it.

selecting this case we would not work stringVar.contains method as it would wrongly match: https://domain.com/21BAD005DD

as an alternate pattern you can try:
grafik
Pattern with escaped dot:
\bhttps:\/\/domain\.com\/21BAD005DD\b

as alternate approach (we assume each line = 1 link) you can try:
isFound = File.ReadAllLines("YourFilePath").Any(Function (x) x.Trim.Equals("YourLinkString"))

1 Like

I just tried your solution and using boundaries \b and scaping the dot, it works.

Thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.