import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { Pattern end = Pattern.compile("\\G\\z"); Matcher mat = end.matcher("this is a test 999"); if (mat.find()) System.out.println(mat.group()); } }