import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExpTest {
public static void main(String[] args){
Pattern p = Pattern.compile("((?<=\\<img.*(?=(http|https)))(http|https))");
Matcher matcher = p.matcher("<img src="http://news.163.com/sports/yao.jpg" src="http://news.163.com/sports/yao.jpg"/>");
System.out.println(matcher.matches());
}
}
程序本身应该没有什么问题,但是运行结果:
Exception in thread "main" java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 27
((?<=\<img.*(?=(http|https)))(http|https))
我Google了半天,最后得到的唯一结果就是换种写法。希望看到这篇文章的朋友,如果已经实现了这种效果,一定要留言不吝赐教。
另外,在我看文档时看到了?:引导的正则表达式,上面说是“匹配不存储”,百思不得其解。感觉还是代码来的实在,写一个看一下: