首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急特殊正则写法!没思路了解决思路

2012-05-23 
急?特殊正则写法!没思路了string RegexString title.+?/titlestring pageStr meta namedes

急?特殊正则写法!没思路了
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"); 

热点排行