Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...