>> I wonder if it is realistic to use a temporary helper buffer to >> implement ^. > > Good idea. Maybe even not a buffer, but just a string. > Are there any differences between buffer matching and string matching? > > Then first we could remove ^ from the search regexp, and when it finds > something, then get the found buffer-substring using text properties > and match it with the original regexp that contains ^. This works surprisingly well. Maybe there are more corner cases, but something already works with quick tests: