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"/>"); 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))