Skip to content

CAT 019

unurgunite edited this page Jul 11, 2026 · 3 revisions

CAT-019 — Regex.new in loop → constant

Field Value
Severity warning
Confidence high
Auto-fix

Regex.new in loop → constant — Creating a Regex inside a loop recompiles the pattern each time. Extract to a constant.

Bad code

3.times { Regex.new("pattern").match(str) }

Good code

PATTERN = /pattern/
3.times { PATTERN.match(str) }

Clone this wiki locally