Regex to escape the parentheses

javascript, regex

Solution

This regex will match the string you provided:

(abc\().+(\)\.def\().+(\))

And using backreferences `$1$2$3` will produce `abc().def()`

Or just use this if you don't want the back references:

abc\(.+\)\.def\(.+\)

Problem

I tried different ways to escape the parentheses using regex in JavaScript but I still can't make it work. This is the string: ``` "abc(blah (blah) blah()...).def(blah() (blah).. () ...)" ``` I want this to be detected: ``` abc().def() ``` Using this code, it returns false. ``` str.match(/abc\([^)]*\)\.def\([^)]*\)/i); ``` Can you please tell me why my regex is not working?

Original source