I would like to generate a regex for a string like "S67-90". I used a syntax "String pattern = "\w\d\d\W\d\d"", but I would like to specify that the first word character should always start wit "S". Can anybody please help me with this?
My sample code is :
String pattern = "\\w\\d\\d\\W\\d\\d";
Pattern p = Pattern.compile((pattern));
Matcher m = p.matcher(result);
if (m.find()) {
System.out.println("Yes!It is!");
}
else{
System.out.println("No!Its not :(");
}
Just replace first \\w with S in your pattern.
String pattern = "S\\d\\d\\W\\d\\d";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With