• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.lang.*;
    4.  
    5. import java.util.regex.Matcher;
    6. import java.util.regex.Pattern;
    7.  
    8. /* Name of the class has to be "Main" only if the class is public. */
    9. class Ideone
    10. {
    11. public static void main (String[] args) throws java.lang.Exception
    12. {
    13. final String regex = "(?<=abc)aa";
    14. final Pattern pattern = Pattern.compile(regex);
    15.  
    16. final Matcher matcher = pattern.matcher("abcaa");
    17.  
    18. final String subMatch;
    19. if (matcher.find()) {
    20. subMatch = matcher.group();
    21. } else {
    22. subMatch = null;
    23. }
    24.  
    25. System.out.println(subMatch);
    26. }
    27. }