How to Print Regex by Captured Group?

Hey Guys,

Can anyone teach me how we’re able to print regex by captured groups when using the match activity?
I have a scenario where I need to extract the name and email address with possibilities of it having different kinds of format.

This is the regex I’m using:

The targeted group I’m trying to capture is group 1 and 3.

I’d be so grateful if you can tell me how I can translate this to print out! Thank you.

Hi @strqsr,

Use Regex.Matches() in assign activity with your regex pattern, this will provide you regex match collection, so you can loop that and get the matching values.

You need to import System.Text.RegularExpression inorder to work with regex in UiPath.

Hi @strqsr,
When you use this regex pattern in Matches activity then you need to set it’s output and you can target it using:
output(0).group(0).ToString where zeroes means the index you want to get. So in your case it will be output(0).group(0).ToString + " " + output(0).group(2).ToString and this should gives you Jim Beam string.

Hey!

Thanks for the solution! I’ve been writing my expression as output.group(1) so I kept getting an error! completely forgot about the index for the actual output ^^;

Thanks a lot!

1 Like

Hi! Thank you for the suggestion, however I actually wanted to just use the matches activity ^^

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