I need a regex that checks is it a quoted (by ') string with possible escaped \' inside. So, I come up with the following regex, \'(\\.|[^\'])*\'
.
"""\'(\\.|[^\'])*\'""".r.findFirstIn(s"'${"a"*100}'")
which works perfectly on small strings, but fails with stack overflow
on size > 3000 bytes.
"""\'(\\.|[^\'])*\'""".r.findFirstIn(s"'${"a"*5000}'")
This is Scala snippets. Internally it runs java.util.regex
, so it's java/jvm problem.
In my knowledge, those simple regex should not cause stack overflow
, it's a simple DFA/NFA without any recursion inside.
How to workaround this issue?
I need regex for that (this is part of parser-combinator code, I can not just write custom code that checks the property).
Why there is recursion inside?