How do i print all the group values from Regex in loop

Hi All,

I have multiple values for same Regex and want to print all the values. Can someone please help me in printing all the group values within the loop.

image

@Naresh_Mandava … if you just want to print the group variable you can try as regexvar(0).groups(1).tostring…groups(2)

You need a loop only if you have set of items reparing for the same regex

So if you could show us what is regex outputs , we could assist better.

Hi @prasath17 … I have to get all the rows in the table, I don’t know how many tables I gonna get. Sometimes I may get 5 rows and then want to print all 5 rows

@Naresh_Mandava Can you provide the regex101 link that you have used in the Screenshot with Data in it ?

@Naresh_Mandava
lets assume you have a many matches returned from Matches Activity - IEnumerable(Of Match):

Bringing all matches into an StringArray (can be done without Loop)
grafik

To String Array
Matches.Select(Function (x) x.toString).toArray
Logging:
String.Join(Environment.NewLine, MatchValues2)

When it comes from Regex.Match(…) Method (MatchCollection)
YourMatchResultVar.Cast(of Match).Select(Function (x) x.toString).toArray
grafik

Similar we can do it for the groups:
arrGroupValue (String Array) = yourSingleMatchVar.Groups.Cast(Of Group).Select(Function (x) x.toString).toArray

@ppr Thank you for help but i want it be in loop because i have to add all this rows into DataTable using add data row

@Naresh_Mandava
in general this request should be solved by the given demo statements.

Lets clear your details:

taken from your screenshot, we got (can you please confirm):

  • Matches is the result from a Match Activity, right? (DataType: IEnumerable(Of Match))
  • each single match (in your loop: item) has groups

accessing the groups:
GroupsArray (String array) = item.Groups.Cast(Of Group).Select(Function (x) x.toString).toArray
Depending if GroupsArray is matching the Datatable Column Structure you can use it for the add Datarow activity

If we have you misunderstood then provide us some more details to your flow and statements. Thanks

2 Likes

Hi @Naresh_Mandava - Please find the starter help here…Regex_Groups.xaml (8.1 KB)

@prasath17 thank you very much for the help.

hi peter it Matches.Select(Function (x) x.toString).toArray its say select is not a member of UiPath.core.activities

@Aleem_Khan IT another Datatype See above

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