tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

I am monkeying with the idea of switching to emacs as my test editor. One major annoyance I'm having is that emacs regexes suffer from "backslashitis" in compared to the much more elegant perl regexes. This makes for frustrations when running search-and-replace operations, and means that I have to backslashify all the regexes I had working for more modern editors. Is there some elegant way of dealing with this? Googling around didn't achieve much.

For what it's worth, it appears that PCRE regexes never made it into emacs search-and-replace because the {} symbols would have gummed up something major, with regards to backwards compatibility.

Any and all wisdom appreciated.

Thanks monks.

UPDATE: Also asked at comp.emacs

UPDATE 2: Anyone got a regex to "emacsify" non-emacs regex? Or "demacsify" emacs regex?

Replies are listed 'Best First'.
Re: PCRE Regexes with Emacs?
by merlyn (Sage) on Aug 25, 2005 at 15:55 UTC
      keep in mind that PCRE isn't really "Perl Compatible"

      I don't find this distinction to be helpful. PCRE is Good Enough. Of course truly compatible Perl regular expressions would allow you to execute arbitrary Perl code, and PCRE doesn't. I cannot imagine why people should be surprised by this.

      When I'm building patterns for Postfix, I'm not particularly fussed by the absence (quite the opposite, in fact). I'm pleased the rest of the functionality is available and that I can avoid POSIX syntax. A pattern that can be elegantly expressed using a positive zero-width lookbehind assertion and/or a negative zero-width lookahead assertion is usually impossible to write for an RE engine that lacks them. That you can't execute Perl code is a comparatively minor inconvenience.

      Having Perl patterns execute Perl code won't be truly useful until the code can do its own pattern matching in turn. Last time I looked, the RE engine wasn't reentrant, or whatever, precluding one from doing such things. It's still an experimental proposition.

      - another intruder with the mooring in the heart of the Perl

Re: PCRE Regexes with Emacs?
by danmcb (Monk) on Aug 26, 2005 at 11:50 UTC

    I don't cimpletely follow all of the above, but I do have an interest.

    I use emacs and use regexp-replace sometimes, it's useful. But being used to perl, I'd be happy if I could just get the basic syntax the same - for instance being able to use \n, \t etc instead of C-c something-or-other.

    Do i need to install another mode or set something in my .emacs for this? It must surely be possible? I have tried to find out before without success. I'd be greatful for an answer.

      Did anybody find a good solution to this annoying problem in the last 6 years since the original post? I am very annoyed by lack of perl style regular expressions (or PCRE) in emacs and don't want to learn the limited emacs regex. I will appreciate an answer or work around?
        I found a work around. Within emacs type C-u M-| and then type your favorite typical perl command to substitute with regex. And of course, this will support perl regex