How to use matches to extract values using regex

Yes, please.

Do you have an understanding of Regex? Or is the entire subject what you’re looking to clarify?

Do you know how to get Regex returns in UiPath on a basic level?

hi @aksh1yadav I want to catch the first object in my regex as well, but I don’t understand how to use the line you wrote above? do I have to put that into the “matches” activity? as of now my regex looks like this:
“((?<=Mail: )\b[^@]+@.+.*[^.]\b.+?)”

I also tested this in the “regex hero” as suggested in another post and I get 2 results for it, as the email adress I try to catch exists two times in this specific email (in other emails it’s possible, that there is only one email adress → which is why I would like to always only catch the first occurence).

Many thanks!
J.R.

@CodeForgePro maybe you can help me solving this problem?

Thanks!

1 Like

Sure!
So you want to put your Regex into the Matches activity. The output for that activity will be a variable that is an Enumerable. Press ctrl K and create the variable to be sure its the right kind.

So you have Matches with the Regex and the Output is an Enumerable variable let’s say: varRegexMatches
You then use an Assign to give another variable any of the returned values:

var1stMatch = varRegexMatches(0) will give you the first result. (computers count from 0 first)
To get the second result, you can use var1stMatch = varRegexMatches(1)

Let me know if that works for you!

I also learned that UiPath uses a relatively strict .Net Regex so I use .NET Regex Tester - Regex Storm to be sure that the Regex I’m making is compatible with the syntax that UiPath uses of Regex.

2 Likes

hi @CodeForgePro, thanks for your quick reply!
I tried to implement your suggestions and in regegstorm it returns the matches perfectly fine:

but in uipath it doesn’t return the value.

the Output from matches is the enumerable “VertretungGefunden”. Then I tried to assign VertretungGefunden(0) to FirstMatchVertretung, which I tried with string and generic value…same for the second match…but when I let it run it doesn’t display the actual match in the message box and an error message or a validation error…

can you tell what the source of the problem is?

Thanks!

You’ll have to manually change the type of your FirstMatchVertretung to Match. Otherwise, you can get directly to the matched string of the first match like this: VertretungGefunden(0).Value, but then you should manually add System.Text.RegularExpressions to your Imports tab to make it easier to work with match variables.

Edit: It’s advisable to verify the number of matches (for example VertretungGefunden.Count > 0) before you access them, because you will get an exception if you try to access an index that does not exist.

1 Like

hi @sfranzen, thanks for your help. so I tried to change this up, at the moment it looks like this:




at the moment I receive the “throw” exception when I run the robot…how can I change it, so that it gives me the “if”-case?

thanks!!!

That should mean you’re actually getting zero matches with the input and pattern you used. Did you test the particular input that led to this with the regex tester and use the same options (case sensitive, single/multiline) as in UiPath? It’s always important to see if there are corner cases that will “break” your pattern, especially if the input is human-generated text.

Edit: Also, since you’re looking at e-mail addresses, this page has a good pattern for it, along with an explanation and lengthy discussion of possible modifications.

2 Likes

@sfranzen I tried a regex from the site you recommended and now it returns the email-address, apparently my regex didn’t work properly although it worked in regexstrom.net. can’t really tell where I f* up, but that doesn’t matter as long as “\b[A-Z0-9._%±]+@[A-Z0-9.-]+.[A-Z]{2,}\b” works just fine :smiley:
thank you so much for your qick help!!!

1 Like

Hi,

i have multiple regular expressions in one text file and i need to match each and every regular expression and extract the value can any one help me in this

thanks in advance

Hi,

This depends on your intent with the results, could you give a more specific description of what you want to achieve? For example, you can combine multiple patterns together with the | (OR) operator, like abc|123|ABC will match occurrences of either of those three patterns. If your patterns are a little more involved than that, or more patterns are likely to be added in the future, it is easier to put them in an array of Strings and use String.Join("|", patternArray) to combine them into a single string.

If the patterns mean something entirely different and you want to keep each pattern’s matches separate, then you can loop over an array of patterns and perform the matching operation and other actions separately for each one.

1 Like

Hi Vinay,

Regex is working fine but I used to pass the string instead of () it is throwing an error.

Thanks
Girish

Bro I need your help can you tell me the regex pattern for something like 1/1 or 2/2 or 1/10 or 7/12. I am trying a lot bro but unable to get it.

Hello,
As this topic is already being discussed, i don’t want to create another topic.

I have multiple PDF attachments which i am downloading from Outlook and reading through all one by one and finding a particular number/Pattern -“100/14-27-061-19W5/0”.
I tried using Substring by taking position of preceding and succeeding words, it works for only a particular set of pdfs having same pattern and containing those succeeding/preceding words but fails for others.
Basically that pattern can be anywhere in pdf and can have dynamic preceding/succeeding words.
So, i though of using Regex, please can you help me with the regex syntax for the above pattern.

"200/14-27-961-19W5/0 ",“1Z0/03-25-061-24W5/0”
Everything is dynamic in the pattern except that length will be 15 and will have a W as shown.

Thanks in advance.

Can you tell me how to extract last two line using regular expression

Single Room 10500 0 10500
Single Room 10500 0 10500
ICU Charges 10500 0 10500
ICU Charges 10500 0 10500
Consultant Charges 16350 0 16350
Investigation Charges 70432 0 70432
Hospital Services 13430 0 13430
Medication Charges 29101 0 29101
Hospital Discount 15785 0 2.5% Hospital Discount Deducted on Medication Charges/- 11.0% Hospital
Discount Deducted on Bill/-

Hi - You can try this.

[H]\w+\s[D]\w+\s\d{5}\s\d\s\d.\d.\s\w+\s\w+\s\w+\s\w+\s\w+\s\w+…\s\d\d.\d.\s\w+\s[D]\w+\s\w+\s\w+\s[B]\w+…

Thanks,
Nitesh

Hi,

I Have some problem to match all the values from a list(of Strings)?
I got with my regex only the last value from the list. and i want to get all values from list(of Strings).

I have a data table with data. I save the third column data into a list(of Strings) and want to split it in 2 columns. I have a for each loop that loops through the list(of Strings) and then I assign Data into the columns i want. But now I just get the last value from the list not all values. Have can this be done? .

Here is my two regex lines:

​System.Text.RegularExpressions.Regex.Match(item.Trim,“(.*)( g)”).Value

and:

System.Text.RegularExpressions.Regex.Match(item.Trim,“(?<=”+ExtractDataTable.Rows(list(of String).IndexOf(item))(“Column3”).ToString+“)(.*)”).Value

Thank you in advance for your help.

Regard, Mikael

Use the function Regex.Split

1 Like