I have a regular expression as following :
var re = new RegExp('(?<!\r)\n', 'g');
which works fine in Chrome,
but gets following error in Firefox :
SyntaxError: invalid regexp group
It also works in node.js
I have a regular expression as following :
var re = new RegExp('(?<!\r)\n', 'g');
which works fine in Chrome,
but gets following error in Firefox :
SyntaxError: invalid regexp group
It also works in node.js
You could use a try/catch expression
try {
var re = new RegExp('(?<!\r)\n', 'g');
}
catch() {
var firefox = true;
//add alternate RegExp
}
you could also check its useragent:
if (navigator.userAgent.indexOf("Chrome") !== -1) {
//Code that works on chrome
} else {
//code for firefox
}
this is because chrome supports look-behind expressions, while firefox doesn't.
source: https://www.w3schools.com/ and https://developer.mozilla.org/