Please study this code. Why does creating the same regular expression in different ways (via / regex / literal and the RegExp constructor) produce a different result? Why doesn't the second pattern match the space in str ?
var str = " "; var pat1 = /\s/; document.writeln(pat1.test(str)); // shows "true" var pat2 = new RegExp("\s"); document.writeln(pat2.test(str)); // shows "false"
Unable to find the answer to my question anywhere. Thanks
source share