正则表达式--非捕获

前端之家收集整理的这篇文章主要介绍了正则表达式--非捕获前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
特殊构造(非捕获) 
(?: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:
a66

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

原文链接:https://www.f2er.com/regex/359188.html

猜你在找的正则表达式相关文章