import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexDemo07 {
public static void main(String[] args) {
String str = "aaa1aaa1aaa1";
String regexStr01 = "(.*\\d)";
String regexStr02 = "(.*?\\d)";
Matcher matcher01 = Pattern.compile(regexStr01).matcher(str);
Matcher matcher02 = Pattern.compile(regexStr02).matcher(str);
if (matcher01.find()) {
System.out.println(matcher01.group(1));
}
System.out.println(".......");
if (matcher02.find()) {
System.out.println(matcher02.group(1));
}
}
}
aaa1aaa1aaa1
.......
aaa1