Stephane Chazelas wrote: > one can > use (?m) if he wants ^ to match the beginning of each line in > the NUL-delimited record instead of just the beginning of the > record. I think the intent is that ^ and $ should match only the line-terminator specified by -z (or by -z's absence). So the sort of usage you describe is unspecified and not supported. That being said, it does make sense to match tricky regular expressions like that line by line, even if this hurts performance. Otherwise, I suspect there are even trickier regular expressions that could reject a buffer full of lines even though it contains matching lines. When in doubt we should avoid optimization so I installed the attached patch into the master branch. Please give it a try.