Have you ever wanted to test out regular expressions in emacs? Until I found out about re-builder I used to run M-x isearch-forward-regexp (also bound to C-M-s) in a buffer until I figured out the expression I needed. This works but just having M-x re-builder in your bag of tricks helps. In the words of the author, Detlev Zundel
When I have to come up with regular expressions that are more complex than simple string matchers, especially if they contain sub expressions, I find myself spending quite some time in the `development cycle’. `re-builder’ aims to shorten this time span so I can get on with the more interesting bits. With it you can have immediate visual feedback about how well the regexp behaves to your expectations on the intended data.
re-builder supports a number of different input forms for the regular expression. The input type can be changed by C-c TAB when you are in this mode.
Read Regexp Syntax in re-builder

Another nice feature is the highlighting of the different subexpression matches. Xemacs has added perl regular expression support to re-builder as noted on the emacs wiki. I hope this gets added back into GNU emacs.
5 responses so far ↓
Update: This post was originally listed as a newbie tip. After some discussion, we decided that Lisp regular expressions, given their unfamiliar syntax, do not fall under the “newbie” category. We moved this into the “quick tip” category instead. Sorry if your feed readers picked up a double post.
Here’s a page that has a nice lisp function that will transform the Lisp regex into a Perl-like regex and put it into your kill ring
http://www-gatago.com/gnu/emacs/help/20224365.html
I didn’t write it — I just googled for it.
I decided to write off re-builder because it was emacs lisp regexp language only until you pointed out “perl regexp support”. It requires a perl binary, but the concept seems useful.
I find re-builder’s syntax modes confusing, perhaps because I’m not familiar with the terminology. It seems the two modes that are important to the beginning user (like me) are “read” and “string”. “string” is the Emacs Lisp regexp that most people are familiar with because it is the same one used in interaction, such as when using isearch-regexp-forward. “read” is the flavor of regexp you write when creating emacs lisp source code.
Compare: Match
"\\\\a2b3c4e5"(with the quotes):string:
"\\\\\\\\\(\w+\)\([a-z]3\)\([[:alpha:]]4\)\(e[[:digit:]]\)"read:
\"\\\\\\\\\\\\\\\\\\(\\w+\\)\\([a-z]3\\)\\([[:alpha:]]4\\)\\(e[[:digit:]]\\)\"Syntax mode can be Customized with reb-re-syntax, but (unfortunately?), the default is the harder-to-type “read” mode. re-builder supports converting a “string” syntax to “read” automatically, so a quick tip would be to use “string” mode.
@MikeH:
I think that it would be more correct to say that the useful lisp function in your link converts “read” syntax to “string”.
piyo: Your comment made me realize I had mis-labeled the title of the example image as string syntax. I have corrected the article. Thanks.
[...] been reading the all-things-emacs blog a lot lately and two of their recent posts talked about packages that I didn’t have in my Emacs. I looked around and [...]
Leave a Comment