I am unable to find any resources on the web for my case.
So I tried to use the following RegExp to escape the brackets and things inside.
Here is the example string:
hjdsoghbesi (saeogbesor) serogberso ersberawsewf(edsrgb) sfdrobersb ouersber
hjdsoghbesi serogberso ersberawsewf sfdrobersb ouersber
hjdsoghbesi sfdrobersb ouersber
Use non-greedy quantifiers:
var str = "hjdsoghbesi (saeogbesor) serogberso ersberawsewf(edsrgb) sfdrobersb ouersber"; console.log(str.replace(/\(.*?\)/g, ""));
* is greedy, it will match as many characters as possible.
*? is lazy, it will match as few as possible.