I guess NFA is the <i>classic</i> regex, but most implementations are vastly more powerful through the introduction of backtracking and back references.<p>In any case, a regex is hilariously unsuitable for the purpose here. It&#x27;s obtuse, it has terrible corner case performance (as noticed here), it probably took vastly longer to write than a simple loop and apparently it isn&#x27;t even correct.