How to compare two regexps?
Since you can store a regexp in a variable
var regexp = /a/;
console.log(/a/ == /a/);
var regexp1 = /a/; var regexp2 = /a/; console.log(regexp1 == regexp2);
both return false?
String(regexp1) === String(regexp2))
You are getting false because those two are different objects.
regex is an object- a reference type, so the comparsion is done by reference, and those are two different objects.
console.log(typeof /a/); // "object"
var a = /a/; var b = /a/; console.log(a.toString() === b.toString()); // true! yessss!
Another "hack" to force the toString() on the regexes is:
console.log(a + "" === b + "");