1
Good afternoon.
I would like to know how to check whether the matcher found something. Because I am searching for information inside a PDF file and when it does not find anything I would like to have a condition that writes "Information not found"
while (matcherAut.find()) { //antes deste WHILE gostaria de ter um if e se o matcher não tiver encontrado nada escrever uma mensagem.
Pattern pattern = Pattern.compile("\\s0.*|\\s1.*|\\s2.*|\\s5.*|\\s6.*|\\s7.*|\\s8.*|\\s9.*|^0.*|^1.*|^2.*|^5.*|^6.*|^7.*|^8.*|^9.*"); // Segundo Filtro (Elimina os que não começam com 3|4)
Scanner scanner = new Scanner(matcherAut.group()).useDelimiter(pattern);
Matcher matcher2 = pattern.matcher(aut);
while (scanner.hasNext()) {
aut = scanner.next();
if (!linhasGravadas.contains(aut)) {
System.out.println("Pagina: " + i);
System.out.println("Autorização: " + matcherAut.group());
/*System.out.println("Autorização: " + aut);
gravarArq.println(aut);
linhasGravadas.add(aut);*/
Aut = Aut + 1;
}
}
}
This REGEX can be written as
"(\\s|^)[12356789].*"
.– Guilherme Lautert