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))