Skip to content Skip to sidebar Skip to footer

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, '

$1'); str = str.replace(/(exception\s+No

Solution 1:

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");

Post a Comment for "Combine Two Regular Expression Into One"