Substring is found, but regex fails

java, regex

Solution

The `.` matches everything except for newline characters. You must change your regex string to

"(?s).*</p:panelGrid>.*"

Then it will match always.

Problem

Suppose I have some string, and run the following tests on it: ``` response.indexOf("</p:panelGrid>"); response.matches(".*</p:panelGrid>.*"); ``` How is it possible that `indexOf` finds the substring (it does not return `-1`), but the regular expression in the second test does not match? I have come across this problem while trying to write a test that checks if taglibs are rendered correctly in JSF with Pax Web. I have not been able to reproduce this behavior outside of this test.

Original source