import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Regex {
public static void main
( String args
[] ) { // String com texto a ser verificado
String texto
= "André Carlos Ferreira da Silva"; // Expressão regular a ser usada
String pattern
= "^([a-zA-ZÈ-Úè-ú]+)\\s"; // Inicialização de RegExp Pattern
Pattern r = Pattern.compile(pattern);
// Inicialização do verificador de pattern em texto
Matcher m = r.matcher(texto);
// Se (matcher encontrou regexp na string)
if (m.find()) {
// escreva o grupo encontrado
System.
out.
println("Olá, " + m.
group(0) ); } else {
// mensagem de erro
System.
out.
println("Você não tem mais de um nome?"); }
}
}
aW1wb3J0IGphdmEudXRpbC5yZWdleC5NYXRjaGVyOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4LlBhdHRlcm47CgpjbGFzcyBSZWdleCB7CgogICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiggU3RyaW5nIGFyZ3NbXSApIHsKICAgICAgLy8gU3RyaW5nIGNvbSB0ZXh0byBhIHNlciB2ZXJpZmljYWRvCiAgICAgIFN0cmluZyB0ZXh0byA9ICJBbmRyw6kgQ2FybG9zIEZlcnJlaXJhIGRhIFNpbHZhIjsKICAgICAgLy8gRXhwcmVzc8OjbyByZWd1bGFyIGEgc2VyIHVzYWRhCiAgICAgIFN0cmluZyBwYXR0ZXJuID0gIl4oW2EtekEtWsOILcOaw6gtw7pdKylcXHMiOwogICAgICAvLyBJbmljaWFsaXphw6fDo28gZGUgUmVnRXhwIFBhdHRlcm4KICAgICAgUGF0dGVybiByID0gUGF0dGVybi5jb21waWxlKHBhdHRlcm4pOwogICAgICAvLyBJbmljaWFsaXphw6fDo28gZG8gdmVyaWZpY2Fkb3IgZGUgcGF0dGVybiBlbSB0ZXh0bwogICAgICBNYXRjaGVyIG0gPSByLm1hdGNoZXIodGV4dG8pOwoKICAgICAgLy8gU2UgKG1hdGNoZXIgZW5jb250cm91IHJlZ2V4cCBuYSBzdHJpbmcpCiAgICAgIGlmIChtLmZpbmQoKSkgewogICAgICAgICAvLyBlc2NyZXZhIG8gZ3J1cG8gZW5jb250cmFkbwogICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIk9sw6EsICIgKyBtLmdyb3VwKDApICk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgIC8vIG1lbnNhZ2VtIGRlIGVycm8KICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJWb2PDqiBuw6NvIHRlbSBtYWlzIGRlIHVtIG5vbWU/Iik7CiAgICAgIH0KICAgfQp9