我做了以下例子:public static void main(String[] args) {
String input="ab";
String regex="(<=a)(b)";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(input);
while (matcher.find()) {
System.out.println("-----------------------------");
System.out.println("总:" + matcher.group());
System.out.println("-----------------------------");
}
}按理说应该输出"b"呀,可是它什么都没有输出,为什么?我听说java有有后瞻呀
String input="ab";
String regex="(<=a)(b)";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(input);
while (matcher.find()) {
System.out.println("-----------------------------");
System.out.println("总:" + matcher.group());
System.out.println("-----------------------------");
}
}按理说应该输出"b"呀,可是它什么都没有输出,为什么?我听说java有有后瞻呀
特殊构造(非捕获)
(?:X) X,作为非捕获组
(?idmsux-idmsux) Nothing,但是将匹配标志由 on 转为 off
(?idmsux-idmsux:X) X,作为带有给定标志 on - off 的非捕获组
(?=X) X,通过零宽度的正 lookahead
(?!X) X,通过零宽度的负 lookahead
(?<=X) X,通过零宽度的正 lookbehind
(?<!X) X,通过零宽度的负 lookbehind
(?>X) X,作为独立的非捕获组
叫法不太一样