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.
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.
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.
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.
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.
After a bit more searching I found a few similar questions:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With