Why is the escape syntax different between two Javascript functions: search vs replace? : <p>Use this string as example</p>

<pre><code>s = "a(b"
</code></pre>

<p>These two work as expected</p>

<pre><code>s.search("\\(")
1

s.replace("\(", "")
"ab"
</code></pre>

<p>But these don't</p>

<pre><code>s.search("\(")
Uncaught SyntaxError: Invalid regular expression: /(/: Unterminated group

s.replace("\\(", "")
"a(b"
</code></pre>

<p>Huh? Why does search require one more escape than replace?</p>

<p>Also, shouldn't string input give a literal search, instead of being interpreted as a regexp? In theory, I shouldn't have to use escape characters at all.</p>
