When you want to know whether a pattern is found in a string, use RegExp#test()
instead of String#match()
and RegExp#exec()
.
This rule is fixable.
if (string.match(/unicorn/)) {}
if (/unicorn/.exec(string)) {}
if (/unicorn/.test(string)) {}
When you want to know whether a pattern is found in a string, use RegExp#test()
instead of String#match()
and RegExp#exec()
.
This rule is fixable.
if (string.match(/unicorn/)) {}
if (/unicorn/.exec(string)) {}
if (/unicorn/.test(string)) {}