import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
class RegexTest {
/* Validação. */
public static final Pattern PADRAO = Pattern.compile (
"^[([\\ p{L}&&[\\ p{IsLatin}]]|0-9| |'|-]+$" ) ;
/* Testes positivos. */
public static String [ ] positivos
= { "á é í ó ú" ,
"ã ẽ ĩ õ ũ" ,
"Á È Ĩ Ã ó" ,
"aeiou" ,
"abc def ghi" ,
"um 23 45" ,
"Um - 2 - tres quatro" ,
"Um' 2 três' quatro" ,
"maçã" ,
"Â Ê Î ô û" ,
"á Ae Éi Ĩô O" ,
"O rato roeu a roupa do rei de Roma" ,
"áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙäëïöüÄËÏÖÜâêîôûÂÊÎÔÛãẽĩñõũÃẼĨÑÕŨçÇ"
} ;
/* Testes negativos. */
public static String [ ] negativos
= { "." ,
"*" ,
"/" ,
"<" ,
"≃" ,
"^" ,
"~" ,
"()" ,
"#" ,
"中国"
} ;
public static void main
( String [ ] args
) { for ( final String s
: positivos
) { boolean b = isValid( s) ;
System .
out .
println ( b
+ ( b
? " ok - " : " oops - " ) + s
) ; }
for ( final String s
: negativos
) { boolean b = isValid( s) ;
System .
out .
println ( b
+ ( b
? " oops - " : " ok - " ) + s
) ; }
}
public static boolean isValid
( final String string
) { return PADRAO.matcher ( string) .matches ( ) ;
}
}
aW1wb3J0IGphdmEudXRpbC5yZWdleC5NYXRjaGVyOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4LlBhdHRlcm47CgpjbGFzcyBSZWdleFRlc3QgewoKICAgIC8qIFZhbGlkYcOnw6NvLiAqLwogICAgcHVibGljIHN0YXRpYyBmaW5hbCBQYXR0ZXJuIFBBRFJBTyA9IFBhdHRlcm4uY29tcGlsZSgKICAgICAgICAgICAgIl5bKFtcXHB7TH0mJltcXHB7SXNMYXRpbn1dXXwwLTl8IHwnfC1dKyQiKTsKCiAgICAvKiBUZXN0ZXMgcG9zaXRpdm9zLiAqLwogICAgcHVibGljIHN0YXRpYyBTdHJpbmdbXSBwb3NpdGl2b3MgPSB7CiAgICAgICAgICAgICLDoSDDqSDDrSDDsyDDuiIsCiAgICAgICAgICAgICLDoyDhur0gxKkgw7UgxakiLAogICAgICAgICAgICAiw4Egw4ggxKggw4Mgw7MiLAogICAgICAgICAgICAiYWVpb3UiLAogICAgICAgICAgICAiYWJjIGRlZiBnaGkiLAogICAgICAgICAgICAidW0gMjMgNDUiLAogICAgICAgICAgICAiVW0gLSAyIC0gdHJlcyBxdWF0cm8iLAogICAgICAgICAgICAiVW0nIDIgIHRyw6pzJyBxdWF0cm8iLAogICAgICAgICAgICAibWHDp8OjIiwKICAgICAgICAgICAgIsOCIMOKIMOOIMO0IMO7IiwKICAgICAgICAgICAgIsOhIEFlIMOJaSDEqMO0IE8iLAogICAgICAgICAgICAiTyByYXRvIHJvZXUgYSByb3VwYSBkbyByZWkgZGUgUm9tYSIsCiAgICAgICAgICAgICLDocOpw63Ds8O6w4HDicONw5PDmsOgw6jDrMOyw7nDgMOIw4zDksOZw6TDq8Ovw7bDvMOEw4vDj8OWw5zDosOqw67DtMO7w4LDisOOw5TDm8Oj4bq9xKnDscO1xanDg+G6vMSow5HDlcWow6fDhyIKICAgIH07CgogICAgLyogVGVzdGVzIG5lZ2F0aXZvcy4gKi8KICAgIHB1YmxpYyBzdGF0aWMgU3RyaW5nW10gbmVnYXRpdm9zID0gewogICAgICAgICAgICAiLiIsCiAgICAgICAgICAgICIqIiwKICAgICAgICAgICAgIi8iLAogICAgICAgICAgICAiPCIsCiAgICAgICAgICAgICLiiYMiLAogICAgICAgICAgICAiXiIsCiAgICAgICAgICAgICJ+IiwKICAgICAgICAgICAgIigpIiwKICAgICAgICAgICAgIiMiLAogICAgICAgICAgICAi5Lit5Zu9IgogICAgfTsKCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgZm9yIChmaW5hbCBTdHJpbmcgcyA6IHBvc2l0aXZvcykgewogICAgICAgICAgICBib29sZWFuIGIgPSBpc1ZhbGlkKHMpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oYiArIChiID8gIiBvayAtICIgOiAiIG9vcHMgLSAiKSArIHMpOwogICAgICAgIH0KICAgICAgICBmb3IgKGZpbmFsIFN0cmluZyBzIDogbmVnYXRpdm9zKSB7CiAgICAgICAgICAgIGJvb2xlYW4gYiA9IGlzVmFsaWQocyk7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihiICsgKGIgPyAiIG9vcHMgLSAiIDogIiBvayAtICIpICsgcyk7CiAgICAgICAgfQogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgYm9vbGVhbiBpc1ZhbGlkKGZpbmFsIFN0cmluZyBzdHJpbmcpIHsKICAgICAgICByZXR1cm4gUEFEUkFPLm1hdGNoZXIoc3RyaW5nKS5tYXRjaGVzKCk7CiAgICB9Cn0=