简体   繁体   中英

Multiple Regex matches in C#

I'm used to web-scraping in Python but now I'm trying to do the same in C#, which seems to be a bit different. The simple thing I want to do is done in python by this regex:

r'<a href="(.*?)">.+name="(.*?)"'

It simply grabs the URL and a name related to that link and returns a 2 dimensional array.

How is this done in C#?

Regex re = new Regex(@"<a href=""(.*?)"">.+name=""(.*?)""");

MatchCollection matches = re.Matches(input);

foreach (Match match in matches)
{
    Console.WriteLine("URL={0}, Name={1}", match.Groups[1].Value, match.Groups[2].Value);
}

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