You were asking why the index/rindex is so good. It's because you're matching a pure literal string, which can use the highly-efficient Boyer-Moore search (the longer the literal string, the faster it tends to be).
For some reason, the "^" is not being optimized properly as an anchor for "/mg" searches. Leaving it out entirely, or substituting the alternate "(?:\A|\n)" pattern, results in searches that are much faster. That seems like a bug in the optimizer. | [reply] [d/l] |