/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
import java.util.regex.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
List
< String
> strs
= Arrays .
asList ( "D99" ,
"M00.0" ,
"M01.6" ,
"J98.3" ,
"T05.0" ,
"M96.81" ,
"D68.20" ,
"9D.0" ,
"6G" ,
"7H." ,
"M96.811" ,
"J234.82" ,
"G687.1" ,
"GU87.11" ) ; test( str) ;
}
public static void test
( final String myString
) { final String rule
= "[A-Z]\\ d{2}\\ .?\\ d{0,2}" ; final Pattern pattern = Pattern.compile ( rule) ;
final Matcher matcher = pattern.matcher ( myString) ;
if ( ! matcher.matches ( ) ) {
System .
out .
println ( "Failure, the String" + myString
+ " is not valid!" ) ; } else {
System .
out .
println ( "Success, the String" + myString
+ " is valid!" ) ; }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwucmVnZXguKjsKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlMaXN0PFN0cmluZz4gc3RycyA9IEFycmF5cy5hc0xpc3QoIkQ5OSIsIk0wMC4wIiwiTTAxLjYiLCJKOTguMyIsIlQwNS4wIiwiTTk2LjgxIiwiRDY4LjIwIiwgIjlELjAiLCI2RyIsIjdILiIsIk05Ni44MTEiLCJKMjM0LjgyIiwiRzY4Ny4xIiwiR1U4Ny4xMSIpOwoJCWZvciAoU3RyaW5nIHN0ciA6IHN0cnMpCgkJCXRlc3Qoc3RyKTsKCgl9CglwdWJsaWMgc3RhdGljIHZvaWQgdGVzdChmaW5hbCBTdHJpbmcgbXlTdHJpbmcpewoJICAgZmluYWwgU3RyaW5nIHJ1bGUgPSAiW0EtWl1cXGR7Mn1cXC4/XFxkezAsMn0iOwoJICAgZmluYWwgUGF0dGVybiBwYXR0ZXJuID0gUGF0dGVybi5jb21waWxlKHJ1bGUpOwoJICAgZmluYWwgTWF0Y2hlciBtYXRjaGVyID0gcGF0dGVybi5tYXRjaGVyKG15U3RyaW5nKTsKCQoJICAgaWYoIW1hdGNoZXIubWF0Y2hlcygpKXsKCSAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRmFpbHVyZSwgdGhlIFN0cmluZyIgKyBteVN0cmluZyArICIgaXMgbm90IHZhbGlkISIpOwoJICAgfSBlbHNlICB7CgkgICAJCVN5c3RlbS5vdXQucHJpbnRsbigiU3VjY2VzcywgdGhlIFN0cmluZyIgKyBteVN0cmluZyArICIgaXMgdmFsaWQhIik7CgkgICB9Cgl9Cn0=
stdout
Success, the StringD99 is valid!
Success, the StringM00.0 is valid!
Success, the StringM01.6 is valid!
Success, the StringJ98.3 is valid!
Success, the StringT05.0 is valid!
Success, the StringM96.81 is valid!
Success, the StringD68.20 is valid!
Failure, the String9D.0 is not valid!
Failure, the String6G is not valid!
Failure, the String7H. is not valid!
Failure, the StringM96.811 is not valid!
Failure, the StringJ234.82 is not valid!
Failure, the StringG687.1 is not valid!
Failure, the StringGU87.11 is not valid!