Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: javascript
regexclean-codesimplificationstring
Collapse redundant chained replaces into a single regex pass
If two sequential replaces achieve one transformation (e.g. whitespace then space-to-dash), combine them into one regex.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | name.toLowerCase().replace(/\s\s+/g, ' ').replace(/ /g, '-'); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | name.toLowerCase().replace(/\s+/g, '-'); // any whitespace run -> single dash |
Explanation (EN)
Objašnjenje (HR)