JavaScript

JavaScript

Made by DeepSource

Found control characters in regular expression JS-W1035

Bug risk
Minor

ASCII character codes between 0 and 32 are reserved for non-printing characters. Such characters are unlikely to be present in JavaScript strings, and matching them with a Regular expression is most likely a mistake. Even when you do want to match them, it is recommended to use the character literals for better clarity:

const tabsAndSpaces = / \t/
const tabsSpacesAndNewLines = /\s/

If you find yourself needing to match the hex values for some reason, consider adding a skipcq comment to inform readers about the use-case. This will also prevent DeepSource from raising the issue.

Bad Practice

const rSpaces = /\x1a/;
// A regex like this one is rarely useful:
const regExp  = new RegExp("\x12");

Recommended

const rSpaces = / /;
const regExp  = new RegExp("[\sa-z]+no-control-chars-here");