Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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

share|improve this question
1  
Where is the problem?? str.replace() ? – Sankalp Mishra May 6 '13 at 12:46
    
RegExp is a native feature on Javascript, so you don't need the quotes, just /^$/.test("string"). – Wesley Schleumer de Góes May 6 '13 at 12:46
    
Drop the appostrophes and at a /g flag if you want to perform a global regex! ;) – Tim May 6 '13 at 12:47
    
oh yes the /g flag – beeant May 6 '13 at 12:49
up vote 2 down vote accepted

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|improve this answer
    
yes, nothing really special other than the /g flag. thank you! – beeant May 6 '13 at 16:32
    
The /s flag is valid PHP but not JS. – Wyatt8740 Jun 16 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.