Earlier quoted context omitted.
That's not really surprising since regex in most languages is PCRE and not really indicative of actual interpreter performance.
If that's the case why is Ruby slower?
- IO.foreach is lazy, but then you call `Array#grep` on it which allocate a huge Array
- `grep` populate the "last_match" object, `String#match?` is much faster.
Try rifraf's snippet: https://news.ycombinator.com/item?id=24597067, it should be as fast as Python.