mpen
mpen

Reputation: 282845

C# Regex: Get all matches w/ name?

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?

Upvotes: 0

Views: 548

Answers (2)

mpen
mpen

Reputation: 282845

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

Hurray for guessing.

Upvotes: 2

SLaks
SLaks

Reputation: 887405

m.Groups["class"]

Upvotes: 1

Related Questions