Pattern pega = Pattern.compile("(oi)*(olá)");
Matcher m = pega.matcher(textoDoArquivo);
while (m.find()) {
//se achar, entra o while
}
}
blablabla oi alex olá blablabla
oi alex olá
vlw galera :thumbup:
Pattern pega = Pattern.compile("(oi)*(olá)");
Matcher m = pega.matcher(textoDoArquivo);
while (m.find()) {
//se achar, entra o while
}
}
blablabla oi alex olá blablabla
oi alex olá
vlw galera :thumbup:
Sua expressão regular está errada. Veja o exemplo abaixo, e corrija sua expressão regular.
import java.util.regex.*;
class TesteRegex {
public static void main (String[] args) {
String[] linhas = {
"Shopping in Italy",
"Italy has always been the model and master of style,",
"taste, and class. It is synonymous with fashion,",
"elegance, design, and most importantly? shopping!",
"\"Made in Italy\" garments, shoes, and furnishings",
"are known for their high quality, design, and glamour.",
"Visitors have so much to choose from among leading national and"
};
Pattern pat = Pattern.compile ("sho(.*)nish");
for (String linha : linhas) {
Matcher mat = pat.matcher (linha);
while (mat.find()) {
// deve imprimir "shoes, and furnish"
System.out.println (mat.group());
// deve imprimir "es, and fur"
System.out.println (mat.group(1));
}
}
}
}