求段正则匹配到这两个div之间的内容,谢各位高手
<divid="name">张三<imgsrc="../arrow.png"/></div>用java写的程序...
<divid="name">
张三
<imgsrc="../arrow.png"/>
</div>
用java写的程序 展开
张三
<imgsrc="../arrow.png"/>
</div>
用java写的程序 展开
展开全部
var reg = /<div[^>]*id[=\"\']+name[\"\']?[^>]*>((?:(?!<\/div>)[\w\W])*)<\/div>/gi;
var html = '<div id="name">\r\n张三\r\n<imgsrc="../arrow.png"/>\r\n</div>';
while (reg.exec(html)) {
console.log(RegExp.$1);
}
-------------------
package com;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Yuma
{
public static void main(String[] args)
{
String html = "<div id=\"name\">\r\n张三\r\n<imgsrc=\"../arrow.png\"/>\r\n</div>";
String reg = "(?i)<div[^>]*id[=\"\']+name[\"\']?[^>]*>((?:(?!<\\/div>)[\\w\\W])*)<\\/div>";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(html);
while(matcher.find())
{
System.out.println(matcher.group(1));
}
}
}
var html = '<div id="name">\r\n张三\r\n<imgsrc="../arrow.png"/>\r\n</div>';
while (reg.exec(html)) {
console.log(RegExp.$1);
}
-------------------
package com;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Yuma
{
public static void main(String[] args)
{
String html = "<div id=\"name\">\r\n张三\r\n<imgsrc=\"../arrow.png\"/>\r\n</div>";
String reg = "(?i)<div[^>]*id[=\"\']+name[\"\']?[^>]*>((?:(?!<\\/div>)[\\w\\W])*)<\\/div>";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(html);
while(matcher.find())
{
System.out.println(matcher.group(1));
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询