求高手写一个正则
原字符串类似于这样
有图片链接的a标签,有文字的标签
- HTML code
<a href="1.html"><img src ..></a> <a href="1.html">文字</a><a href="2.html"><img src ..></a> <a href="2.html">文字</a><a href="3.html"><img src ..></a> <a href="3.html">文字</a>
我想取出有图片的那几组字符串
我使用的正则为 (?i)<a[\s\S]*?><img[\s\S]*?</a>
取的第一个还正确,但取第二个的时候就是得到这些字符串了
- HTML code
<a href="1.html">文字</a><a href="2.html"><img src ..></a>
请高手帮帮忙,感激不尽,
[解决办法]
- C# code
(?is)<a[^>]*><img(?><a[^>]*>(?<Open>)|</a>(?<-Open>)|(?:(?!</?a\b).)*)*(?(Open)(?!))</a>试试
[解决办法]
Regex reg = new Regex(@"(?is)(?<=<img)[^>]*?(?=>)");
[解决办法]
(?i)<a\b[^>]*?><img\b[^>]*?></a>
[解决办法]
- C# code
Regex re = new Regex(@"<a[^>]*><img[^>]*></a>", RegexOptions.Singleline);MatchCollection mc = re.Matches("text");foreach (Match ma in mc){}