All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S6325.html Maven / Gradle / Ivy

There is a newer version: 10.20.0.29356
Show newest version

Why is this an issue?

Using regular expression literals is recommended over using the RegExp constructor calls if the pattern is a literal. Regular expression literals are shorter, more readable, and do not need to be escaped like string literals. They can also be more performant because regular expression literals are compiled only once when the script is loaded.

new RegExp(/foo/);
new RegExp('bar');
new RegExp('baz', 'i');
new RegExp("\\d+");
new RegExp(`qux|quuz`);

Using the RegExp constructor is suitable when the pattern is computed dynamically, for example, when the user provides it. Otherwise, you should prefer the more concise syntax of regular expression literals.

/foo/;
/bar/;
/baz/i;
/\d+/;
/qux|quuz/;
new RegExp(`Dear ${title},`);

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy