How to convert PHP regex to JavaScript regex

15,870

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.

Share:
15,870

Related videos on Youtube

bbnn
Author by

bbnn

Updated on September 26, 2022

Comments

  • bbnn
    bbnn over 1 year

    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

    • Sankalp Mishra
      Sankalp Mishra
      Where is the problem?? str.replace() ?
  • Wyatt Ward
    Wyatt Ward almost 8 years
    The /s flag is valid PHP but not JS.