正则表达式--非捕获
发布时间:2020-12-14 04:23:26 所属栏目:百科 来源:网络整理
导读:特殊构造(非捕获) (?:X) ,作为非捕获组 (?idmsux-idmsux) Nothing,但是将匹配标志i d m s u x on - off (?idmsux-idmsux:X) ,作为带有给定标志 i d m s u x on - off (?=X) ,通过零宽度的正 lookahead (?!X) ,通过零宽度的负 lookahead (?=X) ,通过
特殊构造(非捕获)
(?:X) ,作为非捕获组
(?idmsux-idmsux) Nothing,但是将匹配标志i d m s u x on - off
(?idmsux-idmsux:X) ,作为带有给定标志 i d m s u x on - off
(?=X) ,通过零宽度的正 lookahead
(?!X) ,通过零宽度的负 lookahead
(?<=X) ,通过零宽度的正 lookbehind
(?<!X) ,通过零宽度的负 lookbehind
(?>X),作为独立的非捕获组
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainClass {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("(?=a).{3}");
Matcher matcher = pattern.matcher("444a66b");
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
output: import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainClass {
public static void main(String[] args) {
Pattern pattern = Pattern.compile(".{3}(?=a)");
Matcher matcher = pattern.matcher("444a66b");
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
output: 444 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |