in reply to Regex, capturing variables vs. speed

I can suggest a rationale for why the seperate regexes might be faster. The seperate regexes only need to use Boyer-Moore matching to find the start position for the constant strings in the patter, and then capture for the appropriate amount following that point. With the unified regex it will only find one of the constant strings (iirc, it will be 'chr') and then needs to match right from that point.

Other changes to pattern will play a role in the various runtimes so the above is not the only analysis required, but it does give some insight into how the regex engine will handle your pattern.

---
$world=~s/war/peace/g

  • Comment on Re: Regex, capturing variables vs. speed