The pcre2el Package

In my post the other day on Mike Zamansky’s Dired video, I meant to mention one of the packages he talked about but I forgot. That package is pcre2el, a package to, among other things, convert Perl compatible regular expressions to Emacs-style regular expressions. Many people have trouble with Emacs’ regular expressions because of their syntax. They were originally optimized for working with Lisp so some of the escaping rules are just the opposite of Perl’s (and other) regular expression systems. For example, in most regex systems, parentheses are used for grouping and if you want a literal parenthesis, you have to escape it. Because parentheses are ubiquitous in Lisp, the rule is exactly the reverse for Emacs regexes. These days, of course, most people aren’t writing in Lisp so these rules don’t appear to make sense and are annoying.

For those who find this confusing or annoying, the pcre2el package offers a partial solution. The package is essentially a translator that parses Perl regexes and translates them into Emacs regexes. The two engines are different; Perl regexes have capabilities that Emacs regexes don’t so the Perl syntax supporting those features can’t be translated. Still, if you’d like to work with the Perl syntax instead of switching back and forth, this package may be just what you need. Take a look at Zamansky’s video to see an example of it in action.

This entry was posted in General and tagged . Bookmark the permalink.