I have a regex wich is supposed to check for allowed characters in HTTP headers. I use it for testing string that will be slugified.
My problem is, when I use the literal version I obtain a different result from the Object version of the Regex :
Here is a JSFiddle to demonstrate the issue : https://jsfiddle.net/JosselinTD/tkxhk6fn/
var regexObject = new RegExp("^[A-z\u00C0-\u00ff\u0180-\u024f0-9\s'\.,-\/#!$%\^&\*\-_~\|`+]+$", "gi");
var regexLiteral = /^[A-z\u00C0-\u00ff\u0180-\u024f0-9\s'\.,-\/#!$%\^&\*\-_~\|`+]+$/gi;
var stringTest = 'HackForGood 2016 - León'; // More strings in the fiddle
alert('Test with object : ' + regexObject.test(stringTest) + '\nTest with literal : ' + regexLiteral.test(stringTest));
Is there a reason for the difference in behavior ?