Reply To: perl regex replacing on end of line

Product Compare Forums Multi-Edit Support perl regex replacing on end of line Reply To: perl regex replacing on end of line


It’s not a bug; it’s the expected behavior from any reasonably Perl-like regex engine. The problem is that ^ and $ and \Z and the rest are anchors, not character matches, and do not consume input! So when you match against, say “$”, and replace with anysequence of characters, you’re going to get a location being replaced by a string. And, of course, the next time you attempt the same match, there’s still an end-of-line, so “$” will match again, the replace will do the same thing, and so on, ad infinitum.

The problem here is that you’ve been conditioned by the old Multi-Edit regexes, which were distinctly different in several ways from almost any other regex scheme. Just remember that anchors never consume input text, but only match a location, and you’ll avoid any problems of this sort.