Skip to content

no-control-regex

Reports a control character (below U+0020) in the constant string given to new Regex(...) and the static methods of Regex, written raw or as an escape.

A control character in a pattern is almost never intended: it is invisible in the source, and the pattern then matches a character that the reader cannot see. It is usually the result of a pasted character or of an escape that was written for something else.

To fix, remove the character, or write the one that is meant (\t, \n, \r) with its letter escape.

Reported
class A {
void f(String s) {
Pattern.compile("\u001f");
...
Pattern.compile("a b");
...
csharp:
lint:
rules:
no-control-regex: warn # off (default), warn, error
java:
lint:
rules:
no-control-regex: warn # off (default), warn, error
js:
lint:
rules:
no-control-regex: warn # off (default), warn, error
php:
lint:
rules:
no-control-regex: warn # off (default), warn, error
python:
lint:
rules:
no-control-regex: warn # off (default), warn, error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-control-regex in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-control-regex full