10.用正则表达式 提取网页中的网站链接

前端之家收集整理的这篇文章主要介绍了10.用正则表达式 提取网页中的网站链接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_0@  using System;

@H_404_0@  using System.Collections.Generic;

@H_404_0@  using System.Linq;

@H_404_0@  using System.Text;

@H_404_0@  using System.IO;

@H_404_0@  using System.Text.RegularExpressions;

@H_404_0@  namespace q提取网页中的网站链接

@H_404_0@  {

@H_404_0@  class Program

@H_404_0@  {

@H_404_0@  static void Main(string[] args)

@H_404_0@  {

@H_404_0@  string str = File.ReadAllText("1.htm",Encoding.UTF8);

@H_404_0@  MatchCollection ms = Regex.Matches(str,@"""(http://.+?)""");

@H_404_0@  if (ms.Count!=0)

@H_404_0@  {

@H_404_0@  for (int i = 0; i < ms.Count;i++ )

@H_404_0@  {

@H_404_0@  if (ms[i].Success)

@H_404_0@  {

@H_404_0@  Console.WriteLine(ms[i].Groups[1].Value);

@H_404_0@  }

@H_404_0@  }

@H_404_0@  }

@H_404_0@  Console.ReadKey();

@H_404_0@  }

@H_404_0@  }

@H_404_0@  }

猜你在找的正则表达式相关文章