- 特殊构造(非捕获)
- (?: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: @H_301_46@ 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