简体   繁体   English

将两个正则表达式合并为一个

[英]combine two regular expression into one

I have two regular expression. 我有两个正则表达式。 How can I convert them into one: 如何将它们转换为一个:

str = str.replace(/(\s\(\d+\)|exception\s*\:*)/gi, "<br /><br />$1");
str = str.replace(/(exception\s+No\.\s*\d\:)/gi,"<br /><br />$1");

I want to convert them into one regular expression. 我想将它们转换为一个正则表达式。 How can i do it? 我该怎么做?

thanks in advance 提前致谢

Probably not an optimized regexp but a very simple solution is to combine your regexps with a | 可能不是优化的正则表达式,但是一个非常简单的解决方案是将您的正则表达式与| :

str = str.replace(/((?:\s\(\d+\)|exception\s*\:*)|exception\s+No\.\s*\d\:)/gi, "<br /><br />$1");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM