日期:2014-05-18  浏览次数:20870 次

急?特殊正则写法!没思路了
string RegexString = "<title>.+?</title>";
  string pageStr = "<meta name="description" content="6267 companies listed in 'Agriculture Companies', you can submit free company information here." />";
  string resString = "";
  Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
  MatchCollection matches = reg.Matches(pageStr);
  foreach (Match match in matches)
  {
  resString += match.Groups[1].Value;
  }
  Response.Write(resString+"/Test");

 

实现功能是:取出description里的之间的值,取<title></title> 比较简单,标签有开始有结尾,这个description没有结尾的正则怎写?



------解决方案--------------------
就一个 description,你所谓的之间的值,是什么,举例说明
------解决方案--------------------
把/>"; 当做结尾不行吗
------解决方案--------------------
(?i)<meta[^>]*name="([^"]+)"[^>]*>
C# code

string RegexString = "(?i)<meta[^>]*name=""([^""]+)""[^>]*>";
  string pageStr = @"<meta name=""description"" content=""6267 companies listed in 'Agriculture Companies', you can submit free company information here."" />";
  string resString = "";
  Regex reg = new Regex(RegexString, RegexOptions.IgnoreCase);
  MatchCollection matches = reg.Matches(pageStr);
  foreach (Match match in matches)
  {
  resString += match.Groups[1].Value;
  }
  Response.Write(resString+"/Test");