I’m not sure why, but JavaScript doesn’t appear to have a good way of escaping regular expressions that are provided dynamically. In my case, I was using a string provided as part of a JSON AJAX response, and I realized that it contained a question mark, which has special meaning in a regular expression. [...]