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).
frontend ruleP1universalStack: javascript
htmlparsingdomregex
Parse HTML with a DOM parser instead of regular expressions
Use DOMParser or the browser DOM to parse stringified HTML rather than hand-written regex, which is fragile and error-prone.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codejavascript
| 1 | const imgs = html.match(/<img[^>]+src="([^"]+)"/g); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const doc = new DOMParser().parseFromString(html, 'text/html'); |
| 2 | const imgs = Array.from(doc.querySelectorAll('img')); |
Explanation (EN)
Objašnjenje (HR)