How to convert PHP regex to JavaScript regex
Nothing really special. PHP regex syntax is very much the same as in JavaScript:
str = str.replace(/\(\d*\)|\/\(P\)\//g, "");
You can find more information about regular expressions in JavaScript in this manual from MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions.