18

Say I have a buffer with text. I would like to test a regular expression (ideally Perl type) against my buffer and have Emacs highlight the matches on it.

For example, the following regexp (taken from Wikipedia):

(?<=\.) {2,}(?=[A-Z]) 

would match as follows on the following text:

                    enter image description here

This regular expression in particular matches at least two spaces occurring after period (.) and before an upper case letter.

Does Emacs provide an interactive regular expression matcher for Perl regular expressions?

If the answer to the latter is no:

  1. Is there a reason why native support of Perl regular expressions wasn't (ever) considered in Emacs? (considering that it is a well known standard in Unix/Linux)

  2. How could one proceed about building one such Perl regexp matcher? (perhaps calling Perl under the hood, or pre-converting the Perl regexp to a supported variant?)

2
  • 3
    Emacs regexps predate Perl by some time, and I'm assuming they haven't been changed for backwards-compatibility reasons.
    – shosti
    Sep 23, 2014 at 23:13
  • 2
    Also, you might want to check out github.com/joddie/pcre2el (I haven't used it, so I can't vouch for it).
    – shosti
    Sep 23, 2014 at 23:14

2 Answers 2

17

There are two nice packages for working with perl kind of regexes effectively, which should be used together - visual-regexp and it's extension - visual-regexp-steroids. They are great addition to emacs:

enter image description here

1
  • 3
    To clarify, visual-regexp uses emacs regexp and the steroids version can use PCRE or Python regex as backend. Oct 1, 2014 at 11:27
7

re-builder allows on the fly construction of emacs lisp style regular expressions. I don't know if there is an equivalent package for building Perl regular expressions interactively.

See http://www.masteringemacs.org/articles/2011/04/12/re-builder-interactive-regexp-builder/ for more discussion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.