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.
For example, following code snippet is used for stripping the javascript code in the text
Source code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScriptScrub { | |
def scrub(text) { | |
def regex = ~/(<script.*>)([\s\S]+)(<\/script>)/ | |
def result = text.replaceAll(regex, "") | |
result | |
} | |
} |