If JavaScript, /\.scss$/ is a regex. I want to check whether a regex is exactly the same as another regex, however:
/\.scss$/ === /\.scss$/ // false
How can I do this? Note that I do not care about what the regex matches, I only care about the way the regex is defined.
Use .toString:
/\.scss$/.toString() === /\.scss$/.toString() // true
It's easier to see what is going on when using the RegExp object:
new RegExp("ab+c").toString() === new RegExp("ab+c").toString() // true
whereas
new RegExp("ab+c") === new RegExp("ab+c") // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With