Musings about technology and other neat stuff

BrT random header image

How to match multi-line regular expressions in Emacs Lisp

March 27th, 2007 · 5 Comments

I was trying to fix the Emacs Template Toolkit mode file so that it correctly highlights multi-line directives. I could not find how to tell Emacs to make “.” match also a newline, but I found that the negative clause [^...] will match anything that is not specified, including newlines. So by using it with a rarely used character (such as a linefeed character, which is not commonly used in Unix) I can achieve what I wanted. The original regular expression was:


and the new one is:


If someone knows if it is possible and how to enable multi-line regex matching in Emacs, I’d love to know!

Tags: ·

5 responses so far ↓

  • 1  Dave Cross // Mar 27, 2007 at 4:07 pm

    Ooh… thanks for attempting to fix this. It’s something that has been (pretty low down) on my TODO list for years.

    Please send me patches when you’re finished :-)

  • 2  Hitchhiker // Mar 27, 2007 at 4:20 pm

    Hi Dave – wow! You were really quick in noticing my write up, I guess you do keep an eye on your server logs ;-)

    My patch so far consists of replacing the regex as shown above. If I find a better way of doing it, I will let you know.

  • 3  Tom Weissmann // Aug 7, 2007 at 2:50 pm

    How about using the null character, as in [^]]?

  • 4  Tom Weissmann // Oct 9, 2007 at 10:41 am

    The null character is backslash zero.

  • 5  Hitchhiker // Oct 9, 2007 at 11:20 pm

    Tom: that sounds useful. I will try it out. Thanks!