正则表达式拿到字符串所有img标签
字符串如下a="<p></p>\r\n\r\n<p><imgalt=\"\"src=\"/uploads/ckeditor/pictures/28/content_42a...
字符串如下
a="<p> </p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg\" style=\"width: 533px; height: 800px;\" /></p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/29/content_d01373f082025aaf5d7db824ffedab64024f1a96.jpg\" style=\"width: 499px; height: 710px;\" />呵呵</p>\r\n\r\n<p>哈哈</p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/30/content_0180300244.jpg\" style=\"width: 565px; height: 800px;\" /></p>\r\n"
a.match("<(?i)img(.*?)</(?i)")得到的结果如下:
"<img alt=\"\" src=\"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg\" style=\"width: 533px; height: 800px;\" />"
1:"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg">
为什么只能拿到第一条? 展开
a="<p> </p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg\" style=\"width: 533px; height: 800px;\" /></p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/29/content_d01373f082025aaf5d7db824ffedab64024f1a96.jpg\" style=\"width: 499px; height: 710px;\" />呵呵</p>\r\n\r\n<p>哈哈</p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/30/content_0180300244.jpg\" style=\"width: 565px; height: 800px;\" /></p>\r\n"
a.match("<(?i)img(.*?)</(?i)")得到的结果如下:
"<img alt=\"\" src=\"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg\" style=\"width: 533px; height: 800px;\" />"
1:"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg">
为什么只能拿到第一条? 展开
2个回答
2015-08-25
展开全部
var a="<p> </p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/28/content_42a98226cffc1e1741268be24e90f603728de94c.jpg\" style=\"width: 533px; height: 800px;\" /></p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/29/content_d01373f082025aaf5d7db824ffedab64024f1a96.jpg\" style=\"width: 499px; height: 710px;\" />呵呵</p>\r\n\r\n<p>哈哈</p>\r\n\r\n<p><img alt=\"\" src=\"/uploads/ckeditor/pictures/30/content_0180300244.jpg\" style=\"width: 565px; height: 800px;\" /></p>\r\n";
var reg = /<img[^>]*>/gi;
a.match(reg);
回答完毕,采纳即可
展开全部
循环啊 ????不然匹配到了就返回true 肯定只能拿到第一条啊
追问
这怎么循环
追答
StringBuilder sbuilder = new StringBuilder();
foreach (var temp in Regex.Matches(a, "<(?i)img(.*?)</(?i)")) {
sbuilder.Append(temp.Value.Trim());
}
Console.WriteLine(sbuilder.ToString());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询