Here is a brilliant solution I found somewhere:
Using the Regex
[\s\S]
to fit any character, including newlines because it fits any space or non-space characters. So in your case that would give:
s = s.replaceAll("<table[\\s\\S]+/table>", "");
the double backslashes are to escape the backslash.
Another possiblity is
(.|\n)
which is any character (except newline) or newline which gives:
s = s.replaceAll("<table(.|\n)+/table>", "");
For some reason, on my computer, in certain combinations, when I use (.|\n)+
regex runs into a weird loop and goes into a stackoverflow:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.Character.codePointAt(Character.java:4668)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3693)
which doesn't happen when I use [\s\S\]+
instead. I have no idea why though.