简体   繁体   中英

C# regex capturing only the whole expression and not the individual capture groups

I have this regex to capture type names- first the type name, then the list of generic parameters, and finally the assembly name:

(.*?)\[\[(.*?)\]\], (.*)

And when I run it against a string like this (a simplified version of the fully qualified name of a type):

System.Collections.Generic.List`1[[FrEee.Modding.Formula`1[[System.String, mscorlib]], FrEee.Core]], mscorlib

I get only one match on the whole string:

link

Why are the three capture groups I defined not matching the individual parts of the string?

I was using this code to access the captures:

match.Captures[1].Value

When I should have used:

match.Groups[1].Captures[0].Value

另外,看起来您应该使参数通配符贪婪,以便它不会出现在内括号上:

(?<type>.*?)\[\[(?<parameters>.*)\]\], (?<assembly>.*)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM