开发者

C# Regex: Get all matches w/ name?

开发者 https://www.devze.com 2023-01-19 01:03 出处:网络
I\'ve written a regex... internal static readonly Regex _parseSelector = new Regex(@\" (?<tag>\"+_validName+@\")?

I've written a regex...

    internal static readonly Regex _parseSelector = new Regex(@"
        (?<tag>"+_validName+@")?
        (?:\.(?<class>"+_validName+ @"))*
        (?:\#(?<id>"+_validName+ @"))*
        (?<attr>\[
        \])*
        (?:\:(?<pseudo>.+?))*
    ", RegexOptions.IgnorePatternWhitespace);

Now I want to get all the 开发者_开发知识库"class" bits...

var m = _parseSelector.Match("tag.class1.class2#id[]:pseudo");

How do to retrieve the list class1, class2 from the match object?


foreach (var c in m.Groups["class"].Captures)
{
    Console.WriteLine(c);
}

Hurray for guessing.


m.Groups["class"]
0

精彩评论

暂无评论...
验证码 换一张
取 消