0

I wrote a unit test to help me understand Pattern.quote and for the life of me can't figure out why this test isn't passing.

@Test
public void testRegexEscape() throws Exception {
    String text = "Test";
    String patternString = "es";

    String quoted = Pattern.quote(patternString);
    Pattern pattern = Pattern.compile(quoted);

    Matcher matcher = pattern.matcher(text);

    assertTrue(matcher.matches());
}
hbhakhra
  • 4,206
  • 2
  • 22
  • 36

1 Answers1

4

The characters es, literally, do not match the String value test. They do however appear in the String. You can use matcher#find() to check that.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724