Recently I just realize that in if you want to match "any character" in Java/Groovy, you should not use dot match (.).
The reason is: dot match only works for single line text, will not work for line breaks. For the multiple lines text matching, the solution to match any character is using [\s\S].
Please refer this article for details.