How to compare two regexps?

compare, javascript, regex

Solution

Try this:

String(regexp1) === String(regexp2))

You are getting false because those two are different objects.

Problem

Why do ``` console.log(/a/ == /a/); ``` and ``` var regexp1 = /a/; var regexp2 = /a/; console.log(regexp1 == regexp2); ``` both return `false`?

Original source