Emacs Regular Expressions

Jamie Zawinski notwithstanding, I find regular expressions extraordinarily powerful and useful. Most of us in software engineering use them daily and almost all editors support them. One of the complaints I hear all the time is that Emacs regular expressions are not Perl compatible and therefore hard to learn and use or something.

They are (slightly) different from Perl’s implementation but guess what. Perl regular expressions are different from the original grep / egrep flavors as well and yet we all somehow learned to use Perl’s version. Probably the difference that causes the most problems is parentheses. In most regular expression systems, parentheses are used for grouping and a literal parenthesis must be escaped as \( or \). Emacs inverts this usage because parentheses are so common in Lisp. For me, the most annoying issue is having to use things like [[:digit:]] instead of \d.

In any event, Xah Lee has come to the rescue with his recently updated Emacs Regex Tutorial. He points out the differences and how to deal with Emacs specific issues such as case folding. It’s a short tutorial and well worth taking the time to read.

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