no-control-regex
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”class A { void f(String s) { Pattern.compile("\u001f");... Pattern.compile("a b");...Configuration
Section titled “Configuration”csharp: lint: rules: no-control-regex: warn # off (default), warn, errorjava: lint: rules: no-control-regex: warn # off (default), warn, errorjs: lint: rules: no-control-regex: warn # off (default), warn, errorphp: lint: rules: no-control-regex: warn # off (default), warn, errorpython: lint: rules: no-control-regex: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-control-regex |
full |