Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl-style regular expressions in emacs

Tags:

Is there a way to use perl-style regular expressions in Emacs? I use regexp-builder and query-replace-regexp pretty often but the Emacs-style regexes throw me off sometimes.

like image 583
Cam Saul Avatar asked Apr 06 '13 21:04

Cam Saul


People also ask

What regex does Perl use?

Perl's regexes are more like the Posix extended ones. Basic posix regular expressions use ( and { to match the actual characters, and \( and \{ as special characters, but the Posix extended ones use ( and { for the same meaning as in Perl and \( or \{ to match the actual characters, the same as Perl.

Why is Perl good for regex?

In general, Perl uses a backtrack regex engine. Such an engine is flexible, easy to implement and very fast on a subset of regex. However, for other types of regex, for example when there is the | operator, it may become very slow. In the extreme case, its match speed is exponential in the length of the pattern.

Is Perl regex?

Regex or Regular Expressions are an important part of Perl Programming. It is used for searching the specified text pattern. In this, set of characters together form the search pattern. It is also known as regexp.

What PCRE Perl Compatible regular expressions matching does?

The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own native API, as well as a set of wrapper functions that correspond to the POSIX regular expression API.


1 Answers

After a bit more searching I found a few similar questions:

  • Is it possible to change emacs' regexp syntax?
  • Elisp mechanism for converting PCRE regexps to emacs regexps

It looks like the solutions is to write an elisp function to convert PCRE's to Emacs-style regexes. This code on GitHub looks like a pretty good option.

like image 176
Cam Saul Avatar answered Oct 12 '22 21:10

Cam Saul