title: Replicate the functionality of Java's "Pattern.quote" in a JavaScript RegExp
body: <p>In Java, you might try to make a regular expression that would match the URL <code>stackoverflow.com</code> using <code>Pattern.compile("stackoverflow.com")</code>. But this would be wrong because the <code>.</code> has special meaning in regular expressions. The easiest way to fix this is to write <code>Pattern.compile(Pattern.quote("stackoverflow.com"))</code> which comes out to: <code>Pattern.compile("\\Qstackoverflow.com\\E")</code> which <a href="http://download-llnw.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#quote%28java.lang.String%29" rel="noreferrer">"quotes" the entire string</a>. </p>
  
  <p>I want to do the same thing in JavaScript, but JavaScript's regular expressions don't assign any meaning to <code>\Q</code> and <code>\E</code> and it doesn't look like there is a JavaScript equivalent, so I'm not sure how to go about it. My first thought (see my answer below) is to just put a backslash before any character that has a special meaning in a JavaScript regex, but this seems potentially error-prone and I suspect that someone might know of a better way.</p>
  
  <p>This is for a Firefox extension so Mozilla-specific solutions are okay.</p>