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

wsjrzjp 2012-05-22 02:07:16
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没有结尾的正则怎写?

...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-05-22
  • 打赏
  • 举报
回复
(?i)<meta[^>]*name="([^"]+)"[^>]*>

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");
丿海绵宝宝 2012-05-22
  • 打赏
  • 举报
回复
把/>"; 当做结尾不行吗
bdmh 2012-05-22
  • 打赏
  • 举报
回复
就一个 description,你所谓的之间的值,是什么,举例说明

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧