The Emacs Regular Expression Builder

Emacs’ regular expressions are notoriously tricky. They aren’t Perl Regular Expression compatible and the escaping rules are not always what you’d expect if you’re used to Unix regular expressions. Most of us, therefore, have experienced wasted time and frustration trying to get a complicated regular expression right. Fortunately, Emacs provides a tool to help ease the way: re-builder.

re-builder provides interactive feedback on your regular expression as you build it. Any matches for a partial or complete regular expression are shown in the current buffer. If you have subexpressions, they are highlighted in a different color so you can see if you’re getting what you expected (non-color displays are handled too). If the regular expression is invalid (at any point) re-builder will tell you and you can query the error with 【Ctrl+c Ctrl+u】 to find out why re-builder is complaining.

When you’re satisfied with the regular expression, you can copy it to the kill ring with 【Ctrl+c Ctrl+w】 and then quit re-builder with 【Ctrl+c Ctrl+q】.

Although re-builder attaches itself to the buffer that is current when you call it, you can change the target buffer with 【Ctrl+c Ctrl+b】 and the desired buffer name.

Summary

Key Sequence Action
Ctrl+c Ctrl+u Show Error
Ctrl+c Ctrl+b Change Target Buffer
Ctrl+c Ctrl+w Copy Regular Expression to Kill Ring
Ctrl+c Ctrl+q Quit re-builder
This entry was posted in General and tagged . Bookmark the permalink.