Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert PHP regex to JavaScript regex

I am currently porting my web app codes from PHP to JS.

I am having an issue with this regex. from PHP

/\(\d*\)|\/\(P\)\//

used like this

preg_replace('/\(\d*\)|\/\(P\)\//', '', $string);

how can I convert this to work on JS ?

str.replace();

Thank you in advance

like image 660
bbnn Avatar asked May 06 '13 12:05

bbnn


1 Answers

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.

like image 72
VisioN Avatar answered Sep 17 '22 11:09

VisioN