5

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.

2
  • You probably have escape characters. Commented Aug 22, 2012 at 12:11
  • 6
    Provide a String that exhibits such behavior. Commented Aug 22, 2012 at 12:12

1 Answer 1

7

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

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

Then it will match always.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.