Validate a Matcher

0

Good afternoon.

I would like to know how to check if 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 says "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;
        }
    }
}
    
asked by anonymous 24.06.2016 / 19:11

1 answer

1

You can try using the find () or matches () of Matcher , both return boolean.

In your case:

if (!marcher2.find()) {
    System.out.println("Informação não encontrada");
}
    
24.06.2016 / 22:41