As I was still experiencing the StackOverflow (#29), I decided to look into the actual cause and found this StackOverflow thread: https://stackoverflow.com/a/31691056.
It explains that using (.|\n) or the like, is implemented recursively in the popular JVMs, which consequently causes this issue.
The proposed solution is to use a single dot and set the pattern flag DOTALL which causes the dot to implicitly include new lines.
Since the regex isn't using a recursive implementation for this, it should be safe from StackOverflows.
At least for my simple testing this holds true, so I decided to remove the try...catch block as well since it no longer seems necessary.
As I was still experiencing the StackOverflow (#29), I decided to look into the actual cause and found this StackOverflow thread: https://stackoverflow.com/a/31691056. It explains that using
(.|\n)
or the like, is implemented recursively in the popular JVMs, which consequently causes this issue. The proposed solution is to use a single dot and set the pattern flagDOTALL
which causes the dot to implicitly include new lines. Since the regex isn't using a recursive implementation for this, it should be safe from StackOverflows.At least for my simple testing this holds true, so I decided to remove the
try...catch
block as well since it no longer seems necessary.