Skip to content

Comment on Ruby takes 2min to match a regex

Comments

The issue with the regex seems to be the nested * matcher in the last part, paired with the grouping: ([\/\w \.-]* )* (whitespace added to re to circumvent italisizing by HN).

IIRC this was a pathological case with perl5.0 regexes as well.

Removing one of the redundant * or marking the grouping to be non-capturing with ?: seems to fix the problem.

Looks like the regex optimizer could use some love.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.