如何将 PHP 正则表达式转换为 JavaScript 正则表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16399019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:29:48  来源:igfitidea点击:

How to convert PHP regex to JavaScript regex

phpjavascriptregexnode.js

提问by bbnn

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

我目前正在将我的 Web 应用程序代码从 PHP 移植到 JS。

I am having an issue with this regex. from PHP

我对这个正则表达式有问题。来自 PHP

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

used like this

像这样使用

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

how can I convert this to work on JS ?

如何将其转换为在 JS 上工作?

str.replace();

Thank you in advance

先感谢您

采纳答案by VisioN

Nothing really special. PHP regex syntax is very much the same as in JavaScript:

没什么特别的。PHP 正则表达式语法与 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.

您可以在MDN 的本手册中找到有关 JavaScript中正则表达式的更多信息:https: //developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions