How to get List of Group 1 Matches from List of String

Hi, I need to get data from Group 1 of Matches. Let’s say:

Input: varFileList = {“111122223333.pdf”, “444455556666.jpg”} ,
Output: varNumList = {“111122223333”,“444455556666”}

I already have the regex pattern, I just need to know how to achieve this using linq. Thanks!

Hi @mnlatam ,

Assuming that Matches Activity is used, or you already have the Output as MatchCollection type we can consider the below.

Let’s say you have the MatchCollection output variable as matchesList.
The below Linq Expression would provide you the values present in the Group 1 of match in the String array format.

matchesList.Cast(Of Match).Select(Function(x)x.Groups(1).ToString).ToArray

Apologies if I misstated the problem, how can I connect your linq expression if I have List of String as my input?

@mnlatam ,

If the Input is a List of String Array that you want to use Regex and Find the Group 1 Match, then below Expression should do the Trick.

varList.Select(Function(x)System.Text.RegularExpressions.Regex.Match(x,"yourRegexPattern",RegexOptions.IgnoreCase).Groups(1).ToString).ToList

If the above doesn’t work, we would like to Check the Regex Expression that you use.

1 Like

This works for me. My mistake was I was using Matches instead of Match. Thanks @supermanPunch

1 Like

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