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?)

Malabarba
  • 22,878
  • 6
  • 78
  • 163
Amelio Vazquez-Reina
  • 5,157
  • 4
  • 32
  • 47
  • 3
    Emacs regexps predate Perl by some time, and I'm assuming they haven't been changed for backwards-compatibility reasons. – shosti Sep 23 '14 at 23:13
  • 2
    Also, you might want to check out https://github.com/joddie/pcre2el (I haven't used it, so I can't vouch for it). – shosti Sep 23 '14 at 23:14

2 Answers2

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

welldan97
  • 516
  • 5
  • 9
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.

dgtized
  • 4,169
  • 20
  • 41