samedi 29 octobre 2016

How to detect when pattern matcher find finds invalid input?

Matcher.find() looks for any expression specified in the regular expression given to the pattern, but how can we detect when an expression not specified in the regex?

    String input = "& 9 then %"
    Pattern pattern = Pattern.compile(\\(|then|def|then|[0-9]+);
    Matcher match = pattern.Matcher(input);

       while (match.find()) {
       ...
       ...
    }

The input has the symbol & and % which will not be detected, but I want to throw an exception when these symbols are not, so how can I detect that?

Aucun commentaire:

Enregistrer un commentaire