日期:2014-05-20 浏览次数:21031 次
public static void main(String[] args) { String str = " <title> 21212145424<title> 21212145424发动@#$%机雕刻家大家fdf </title> fdf </title>"; Matcher m = Pattern.compile("<title>(?!.*?<title>).*?</title>").matcher(str); while(m.find()){ System.out.println(m.group()); } }
------解决方案--------------------
.*?那个"?"去掉就可以了
------解决方案--------------------
<title>[^<>]*</title>
------解决方案--------------------
import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestConvert { public static void main(String[] args) { String html_line = "<title> 21212145424<title> 21212145424发动@#$%机雕刻家大家fdf </title> fdf </title>"; String result = null; Pattern p = Pattern.compile(".*(<title>.*?</title>).*");// Matcher m = p.matcher(html_line);//开始编译 while (m.find()) { result = m.group(1);//获取被匹配的部分 } System.out.println(result); } }
------解决方案--------------------