0

I have a string that looks like this:

the quick brown (error) fox jumps over (error) the lazy dog (error)

I want to output this string without "(error)", so I apply the following code:

str = str.replace(new RegExp('(\(error\))', 'g'),'');

However, after I run this code the string turns into this:

the quick brown () fox jumps over () the lazy dog ()

How do I get rid of those parenthesis and why are they not removed even though I escaped them and captured them?

Nikita Karamov
  • 517
  • 1
  • 5
  • 18
  • `"the quick brown (error) fox jumps over (error) the lazy dog (error)".replace(/\(error\)/g,'')` – Dalorzo Apr 12 '17 at 18:12
  • 2
    The backslashes you escape special chars with must be literal backslashes. In double quoted string literals, the literal backslash is represented with double backslashes. In a regex literal, you can use a single backslash to escape special regex chars. – Wiktor Stribiżew Apr 12 '17 at 18:18

0 Answers0