Iterating Regular Expression Nouns

I am trying to iterate each named group in a regular expression (i.e. - (?<name>.*) ) And depending on the name of the group set the instance property or add it to the collection. The important part: I will never know the name of the group when using the regular expression, so I can not use the index in my match. Is there a way to extract the names for my groups in my match?

+4
source share
1 answer

You can use Regex.GroupNameFromNumber to repeat all captured groups in the regular expression and search for their names.

+4
source

Source: https://habr.com/ru/post/1302298/


All Articles