I'm building a developer tool, and in one input field my users can input regular expressions.
If they enter an expression that tries to match a literal ?
character anywhere then they've probably made a mistake, as I know that ?
specifically is guaranteed to never appear in the string to match (and if they're trying to spot one, then there's a different action they should take instead). I would like to show a warning in that case.
How can I quickly check from a string containing a regular expression whether it contains a literal ?
character? E.g. I want to warn about regular expression strings like hello\?
, but not https?
.
Detecting \?
is probably a good start, but I imagine there's other cases too.
I'm building this in JavaScript. Solutions based on simple string processing are preferable to fully parsing the regular expression, if possible.