How to detect if a certain regex string is "simple", that is it could be replaced with a simple string (and by that avoid using regex at all).
For example:
input regex simple text form (if possible)
--------------------------------------------------
foo\.bar ---> foo.bar
foo ---> foo
ba\[12\]r ---> ba[12]r
ba.*foo ---> (not possible to represent as plain string)
Basically I'm looking for the opposite of the mythical RegExp.escape
described in this answer, a RegExp.unescape
, that would either do the opposite of mentioned RegExp.escape
or report in some way that the conversion is not possible.
Looking for a JavaScript solution, but Java is also acceptable.