读书人

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

发布时间: 2012-05-23 13:44:13 作者: rapoo

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

读书人网 >C#

热点推荐