RegExp.escape is safe
Assumptions:
This cannot lead to context escapes.
And these sequences have the same
meaning (or will error) everywhere*.
Exhaustive list of contexts
Proposed future contexts
Exception: immediately after `\`.
That does not seem like a real risk.
new RegExp("\\x" + RegExp.escape(user_val))
user_val = "20andthensomestuff"
Also if you put them in an x-mode comment they behave as a comment, which is what you wanted.
Similarly in a group name they are a group name (or an error), in a `{...}` repetition they are a count
(or an error) etc.
Please can we just have this.
Please.