Pattern: Regular expression starting with =
Issue: -
Using =
at the beginning of a regular expression can be mistaken for a division assignment operator (e.g., /=
). This confusion can lead to bugs and reduced code readability.
Example of incorrect code:
function bar() {
return /=foo/;
}
const regex = /=test/;
Example of correct code:
function bar() {
return /[=]foo/;
}
const regex = /\=test/;