Pattern pattern = Pattern.compile(\"^[a-z]+$\"); String string = \"abc-def\"; assertTrue( pattern.matcher(string).matches() ); // obviously fails
I
This works for me
Pattern p = Pattern.compile("^[a-z\\-]+$"); String line = "abc-def"; Matcher matcher = p.matcher(line); System.out.println(matcher.matches()); // true