Why does Regex.Match return only 1 result?

I use a regex that removes href tags from an html document stored in a string. The following code is how I use it in my C # console application.

Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']");

        if (m.Success)
        {
            Console.WriteLine("values = " + m);
        }

However, it returns only one result, and not a list of all href tags on the html page. I know this works because when I try RegexOptions.RightToLeft, it returns the last href tag in the string.

Is there something with my if statement that prevents me from returning all the results?

+3
source share
2 answers

Match Match es, , , m.NextMatch() . :

    Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']");
    Console.Write("values = ");
    while (m.Success) 
    { 
        Console.Write(m.Value);
        Console.Write(", "); // Delimiter
        m = m.NextMatch();
    }
    Console.WriteLine();
+2

, .

+15

All Articles