如何将PHP正则表达式转换为JavaScript正则表达式 [英] How to convert PHP regex to JavaScript regex
本文介绍了如何将PHP正则表达式转换为JavaScript正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正将我的网络应用程序代码从PHP移植到JS。
I am currently porting my web app codes from PHP to JS.
我遇到了这个正则表达式的问题。来自PHP
I am having an issue with this regex. from PHP
/\(\d*\)|\/\(P\)\//
像这样使用
preg_replace('/\(\d*\)|\/\(P\)\//', '', $string);
如何将其转换为适用于JS?
how can I convert this to work on JS ?
str.replace();
提前谢谢
推荐答案
没什么特别的。 PHP正则表达式语法与JavaScript非常相似:
Nothing really special. PHP regex syntax is very much the same as in JavaScript:
str = str.replace(/\(\d*\)|\/\(P\)\//g, "");
您可以在本手册中从 MDN : https://developer.mozilla.org/en-US/docs / JavaScript / Guide / Regular_Expressions 。
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.
这篇关于如何将PHP正则表达式转换为JavaScript正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文