Archives

Creative Commons License
This blog is licensed under a Creative Commons License.

A regular expression IDE for Emacs

| 19 Comments | No TrackBacks

I’ve started work on a new mode for Emacs, which intends to be something like an “IDE” for regular expressions. There are similar tools out there, such as [Reggy][] for OS X and [The Regex Coach][] for Windows. But the former doesn’t show me subgroup matches, and the latter won’t run on OS X. Which made me wonder, wouldn’t this be easy to do in Emacs? Three hours later says yes.

After downloading regex-tool.el, put it somewhere where your Emacs can see it (typically /usr/local/share/emacs/site-lisp), and then add this to your .emacs file:

(load "regex-tool" t)    ; load regex-tool if it's available

Then type M-x load-file and load it manually for your current session. Once that is done, type M-x regex-tool to start the show. It will create a new Emacs frame for you looking something like this:

regex-tool.png

The *Regex* section starts out blank, awaiting you to type in your regular expression. The default syntax is Emacs; if you would prefer regex-tool to use full Perl regular expressions, type the command M-x customize-group, choose the group regex-tool, and then change the backend to “perl” by clicking on the Value Menu. When configured to use Perl, regex-tool will actually invoke a real Perl subprocess to run your matches against, so you can use whatever syntax your installed version of Perl accepts.

The matched parts of the sample string are highlighted in bold red, and all the matching subgroups (including group 0, to show the whole match) are indicated in the *Groups* buffer.

I’m sure there are many ways this little tool could be extended, so please don’t hesitate to send me a note with your suggestions. Or find me in the #emacs IRC channel, on the server irc.freenode.net. I’m johnw on there, and am online most evenings.

No TrackBacks

TrackBack URL: http://www.newartisans.com/mt/mt-tb.cgi/31

19 Comments

It was accidentally deleted by a nightly upload script. It is back now.

Installed. Thank you so much!

*Group* is a bad buffer name, it conflicts with Gnus. :(

Oh it’s *Groups*. Duh. Sorry.

Very nice work, especially with the perl integration.

(BTW, for a good OSX regex explorer, look at RegExhibit.)

sorry if I am missing the point. how is it different from good old re-builder:

http://cvs.savannah.gnu.org/viewvc/checkout/emacs/emacs/lisp/emacs-lisp/re-builder.el

Nice tools. But I now have a bug report for it :) It will enter into the dead loop if only typing “^” in the Regex buffer, since (re-search-forward “^” nil t) will not move the point forward….

Same problem when a single “$” as well.

Thanks, I’ll fix those right away Brian.

Yaroslav: re-builder is for making Emacs regexps which are intended to be part of a string. Only. Mine can be used for testing Perl regexps that are used in a // expression in Perl, for example.

Thanks for this tool, it works like it should on Windows. I like it enough to cart it around. Too bad I don’t have perl installed.

I modified my copy so that it doesn’t call the external process on every keypress, group 0 character position, and added “support” for ruby or any other callable executable. If you want to take a look at it I can send it to you.

BTW, is the defgroup definition correct?

Having not much need for regexp in my current interests I can’t think of any other things I want except for Java regex support, a cheatsheet (ah heck just use yer browser), a “busy” status display, support for regex mode setting (instead of just /mg), regex flavor displayed in the statusbar, and more (defcustom)s.

How to avoid the slow external startup? (Ruby, Java) Make a regex server and do some IPC?

I’d love to see your changes, piyo. I want to add a good extensions mechanism for adding in custom backends and switching on the fly. Also, a cheat sheet is not a bad idea!

I’m using Xemacs 21.4.20 on an Ubuntu Gutsy box. When I try to load the file (or type M-x regex-tool on the minibuffer) it complains about some functions:

Compiling file /usr/local/share/emacs/site-lisp/regex-tool.el at Wed Mar 26 16:02:26 2008
While compiling the end of the data:
  ** The following functions are not known to be defined: 
    make-frame-command, remove-overlays, overlay-put, make-overlay

I’ve tried to find documentation make-frame-command as a function but my elisp has none.

What have I done wrong? What can I do to work it out?

Thanks, Nacho

You’ve done nothing wrong, I just never tested regex-tool on XEmacs. For example, XEmacs uses “extents” instead of “overlays”. The code shouldn’t take long to port, but I’m afraid it will have to be an XEmacs expert who does so; I never use it.

Is it possible to add flags and enter the expression like this?

/mystring/si

Hi Thomas, at present no.

This sounds like the answer to my prayers.

I can’t seem to download it, though. The link is broken.

what else has to be escaped in addition to parenthesis? This becomes slightly tedious as longer expressions must be stripped of the escape characters before use But I assume this is a side-effect of the lisp implementation in emacs.

Hi. I wanted to drop you a quick note to express my thanks. I have been reading through your blog for a few days or so and have picked up a heap of excellent information as well as enjoyed the way you’ve structured your site. I’m attempting to run my very own blog however I think its too general and I need to focus more on smaller topics. Being all things to all people isn’t all that its cracked up to be :-)

About this Entry

This page contains a single entry by John Wiegley published on October 29, 2007 2:48 AM.

Script of the week: sizes was the previous entry in this blog.

Script of the week: bzdmg is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recent Comments

  • Curt Sampson: That there’s “no state” in Haskell is quite wrong; in read more
  • rv: Hi. I wanted to drop you a quick note to read more
  • John Wiegley: It’s here: http://ftp.newartisans.com/pub/python/modpython_gateway.py read more
  • Leon: The file “modpython_gateway.py” Is no longer available in the downloads read more
  • Kathy: Well, the article is really the sweetest on this laudable read more
  • mr.design: Hi John, I just started to read your GFTBU, it’s read more
  • yoman: “Barfin”? “Slurping”? “Slime” “Hunchentoot” ??? What in the T.F. world read more
  • John Wiegley: Something like this is slated for the next release of read more
  • womens health: According to me, Apple has implemented something called blocks, which read more
  • Bjorn Tipling: Why would you add instructions for installing an editor when read more
OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.261