I want to write a regex where a string has (9 characters) and start with either "g" or "r" and then are all numbers afterward.
I have written this but it does not work:
public static void main(String[] args) {
String id= "g57895452";
String pattern = "/^g([0-9]+){8}$/";
if (id.matches(pattern)) {
System.out.println("true");
} else {
System.out.println("false");
}
}
ifyou can simply useSystem.out.println(id.matches(pattern)).