Yes … but How do I use that in uipath?
You asked for Matches activity in your post, use it.
Enter your string and regex pattern.
Ctrl+k in the output and enter the variable name(ienumerable)
Do for each ienumerable, type argument as object.
It works almost perfectly … for input string “abcdef (49)”
I get item(0)= abcdef
item(1) = " "
item(2) = 49)
I thought I understand regex’s but I cant figure out this pattern
Do you understand why it’s matching the )
I suppose you can always use the substring method for strings and get the 3 values you want. Just get the index of “(” and “)” and then you can use the substring method accordingly.
For me it is only giving first past but substring working for me. Incase if you wanna try :
String Match.xaml (8.3 KB)
Probably the regex got changed(tried to bold it and changed back) when I pasted, but the one in the link is correct
regex_Matches.xaml (6.2 KB)
So cool! Thank you thank you thank you!
I have use “Matches” activity, and I want to catch the first element of the result.
Did you know how can I do?
Please try this and let me know
Thank @aksh1yadav! It works.Did you know why we could not use Cast.Groups(0)?
I’m trying to put regex into a matches box and I’m getting this error,
The output variable is |Enumerable type,
Regex should go between quotes in pattern property
Thanks so much!! That worked.
Finding out how to use Regex, (now that I’ve learned that Regex even existed while trying to figure out this issue) within UIPath opens up an entire world of powerful commands to be integrated.
I really appreciate your help! Thank you!
That’s because Groups are a special property of the Match class; they only work if you use special “capturing groups” in your pattern. For example, suppose we want to test the input
with the pattern
using the Matches activity. This will give you a list of Match objects (
IEnumerable<Match>), let’s call it
matches, with one element. Let’s call this first match
match = matches.First. You may also have to add
System.Text.RegularExpressions to your imported namespaces for everything to work and autocomplete properly.
Now, the whole pattern matches the substring
defghi123, which is stored in
match.Value, but it also contains two unnamed groups and one named group “foo”. The unnamed groups are indexed from 1, so you will find that
ghi. The second of these, at the end of the pattern, is optional and was not present in the input; you can test for this with the property
match.Groups(2).Success (False in this case). Named groups behave just the same but are accessed by string identifiers:
For those wanting to know all the details (there are many, many more) about regular expressions in .NET, I suggest you start here.
Thank a lot, @sfranzen, now it’s clear to me.
Hi, can I know how do one determine the pattern? What is with the Group(1)?
Still looking for an answer on this?
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:
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).