Is there any way to construct a regex which will be treated as only literal values, and stop processing it as a regex pattern? e.g. can I prefix or wrap it with some special sequence?
I'm using software based on the re2 library / syntax. I would like to prevent it from treating an entire string as a regex.
I tried using the comment syntax (?#text)
, but the re2 documentation states this is not supported and that seems to be the case.
Background:
I am working with an application that embeds re2 and uses it for string processing. (Happens to be EnergyPlus). As far as I can tell, it will always process certain strings assuming they follow regex syntax. There is no way I can find to tell it not to do that.
We have some cases where user-entered values have to be escaped to prevent this interpretation. For example, we need to replace ?
in any of these strings with \?
to prevent an error. We could do this for all the special chars in re2 but it would just be simpler if we could treat the entire string as not a regex pattern.
The re2 docs on https://github.com/google/re2/wiki/Syntax only mention escaping individual chars.
If it matters the strings originate from C# code, though I don't think that is very significant.