import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegExp {
public static void main(String[] args) {
String instanceName = "pod3cgs02";
Pattern digitPattern = Pattern.compile("\\d{2}$");
Matcher matcher = digitPattern.matcher(instanceName);
System.out.println(digitPattern.matcher(instanceName).matches());
if (matcher.find()) {
System.out.println("find() found substring \"" + matcher.group()
+ "\" starting at index " + matcher.start()
+ " and ending at index " + matcher.end());
}
}
}
No comments:
Post a Comment