Remove duplicate IENumerable<Match>

hello guys! I’m trying to remove duplicate items from a list that was queried by regex.
I used atictivities Matches to get the values I needed, but in Invoice contains different and repeated values, I just want the different values.
So I’m trying to use some method as distinct but as the return is an IEnumerable can’t handle it

1 Like

Hey @rafael.murakami

Distinct - Should work fine.

Could you please xplain or show screenshot on what is the issue pls…


1 Like


If you need array of Match.Value, the following works.

arrString = result.Select(Function(m) m.Value).Distinct().ToArray()

If you need array of Match which is distinct by its Match.Value, the following will work.

arrMatch =  result.GroupBy(Function(m) m.Value).Select(Function(g) g.First).ToArray()

note : result is IEnumerable<Match>


1 Like


the result of my regex for the capture of information is returning as follows

Order { [4501141376], [4501141376], [4501141376], [4501141376], [4501141376], [4501141376], [4501141374], [4501141374], [4501141374], [4501141374], [4501141374], [4501141374], [4501141374] }

i’m wanting the distinct to leave as follows

Order { [4501141376], [4501141374] }

a tried Order.Distinct(), but it’s not working

my variable IEnumerable name is Order


We cannot get expected result using Distinct for Match class directly, because it checks equivalence by its refer address. So we need to use Match.Value : content of Match string.

If you need IEnumerble<Match> as result, the following will work.

Order = order.GroupBy(Function(m) m.Value).Select(Function(g) g.First)


If you need just content of Match, the following is better.

arrString = Order.Select(Function(m) m.Value).Distinct().ToArray()

arrString is String[]


1 Like

Solution. Thanks