正規表現を使用して HTML から URL を取得しようとしていますが、うまくいきません。
<h3 class="(.*?)"><a onmousedown="(.*?)" href="(.*?)">(.*?)</a></h3>
誰かがこれを手伝って説明してくれませんか.私は正規表現が得意ではありません.
編集:
私はどこからでもコードを「つかむ」わけではありません。私は正規表現について長い間知っていましたが、あまり使ったことはありませんでした。このプロジェクトに役立つ可能性があると考えたので、試してみました。これが私のコードです:
static void Main(string[] args)
{
WebClient wc = new WebClient();
String html = wc.DownloadString("http://www.example.com/");
foreach (String result in match("<h3 class=\"(.*)\"><a onmousedown=\"(.*)\" href=\"(.*)\">(.*)</a></h3>", html))
{
Console.WriteLine("result: " + result);
}
Console.ReadKey();
}
public static ArrayList match(string regex, string html, int x = 0)
{
ArrayList l = new ArrayList();
foreach (Match m in new Regex(regex, RegexOptions.Multiline).Matches(html))
{
l.Add(m.Groups[x].Value);
}
return l;
}