Im new to UiPath but have used regex previously within python. I know how to write an expression and pull out each single group using python e.g $1 $2 etc. but in UiPath im not sure how you would pull out each group seperately. I have used the Matches activity to input my regex and the string i am inputting and have tried to seperate the output by using a foreach and circle through each item however it dosent seperate the groups. it just keeps outputting as one line
e.g.
That is currently what i am using. It might just be me expecting it to be seperating the output with the first message box showing
Testing
And the second message box showing
test
If anyone could help me with working out how to seperate the groups to seperate outputs that would be a massive help
Is there anyway of doing this with regex though? cause i was hoping to be able to use a match to find a email for example and then split the email into sperate parts and output
e.g output everything before @ and everything after Seperately.
I have tried to use your method but because of the fact regex is stored in an IEnumerale it cant use split and cant be converted to a string in order to use split
I had the same question as the one in the original post and didn’t want to settle on the Split solution
Here’s my solution:
The Matches activity will return an IEnumerable<Match> and Match has a Groups method which returns a GroupCollection.
So if my activity output variable was matchOut and I wanted to get the first group in the first match instance, I would need:
matchOut(0).Groups(1).Value
Note that I used Groups(1).value because Groups(0).value would return the whole matched string, so matchOut(0).Groups(0).Value would be equivalent to matchOut(0).Value
I had a similar question and struggled with the syntax for using regex groups in UiPath. Attached is another answer for Leon.Walker that uses Regex.Replace and callbacks: $1 $2 etc to solve the problem using the same Pattern from his question “([A-z]*).([A-z]*)”
I’m searching for word pairs in a given text with each word being in a group.
Then I’m iterating through the matches and for each match I’m iterating through the groups and printing the Value.
The output shows the indices for the match and the group and it’s easy to see the difference between Group(0) and Group(>0).