How to pull out Regex groups in UiPath Seperately

uipath
regex

#1

Hello,

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.
Capture
Capture1
Capture2

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


#2

Hi

Try using Split method: https://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1


#3

Hi,
Here we go.
splitTest.xaml (9.7 KB)


#4

Thank you for that :slight_smile:

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


#5

Hi,
It’s only matter of replacing string with regex .
For mail part i think you can check this post

Using your regex expression ([A-z]).([A-z])"
splitTest.xaml (9.8 KB)


#6

Awesome thank you so much for your help :slight_smile:

Im just so use to how regex is used in python my head couldnt grasp how to solve it.

Thank you


#7

Hi,

I had the same question as the one in the original post and didn’t want to settle on the Split solution :slight_smile:

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