正则表达式--非捕获

前端之家收集整理的这篇文章主要介绍了正则表达式--非捕获前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 特殊构造(非捕获)
  2. (?:X) ,作为非捕获组
  3. (?idmsux-idmsux) Nothing,但是将匹配标志i d m s u x on - off
  4. (?idmsux-idmsux:X) ,作为带有给定标志 i d m s u x on - off
  5. (?=X) ,通过零宽度的正 lookahead
  6. (?!X) ,通过零宽度的负 lookahead
  7. (?<=X) ,通过零宽度的正 lookbehind
  8. (?<!X) ,通过零宽度的负 lookbehind
  9. (?>X),作为独立的非捕获组
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class MainClass {
  5. public static void main(String[] args) {
  6. Pattern pattern = Pattern.compile("(?=a).{3}");
  7. Matcher matcher = pattern.matcher("444a66b");
  8.  
  9. while (matcher.find()) {
  10. System.out.println(matcher.group());
  11. }
  12. }
  13. }

output: @H_301_46@ a66

  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class MainClass {
  5. public static void main(String[] args) {
  6. Pattern pattern = Pattern.compile(".{3}(?=a)");
  7. Matcher matcher = pattern.matcher("444a66b");
  8.  
  9. while (matcher.find()) {
  10. System.out.println(matcher.group());
  11. }
  12. }
  13. }

output: 444

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