Powershell Select-String: Get results by named regex group

Question:

I have this Select-String using a regex containing a named group

Select-String does its job:

I can get the value of the matching named group by using the index of the group, no problem:

But I have no success in getting the same result by using the named regex group (mylabel). I found statements like $m.Matches.groups["mylabel"].Value but that doesn’t work on my machines (W10/W2012, PS 5.1)

Answer:

You got one correct answer in the comment above, but here is how to do it without using the 0 match index:

Source:

Powershell Select-String: Get results by named regex group by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply