Index syndication
comment syndication

Switching to multi-line mode using Textmate Regex

December 2, 2008 at 22:57 · Filed under apps, mac, regex, tech

So you have a pattern you want to match across multiple lines, and you have a regular expression that matches it.
You will probably be used to doing this in perl like this:
or using regex in ruby like this:
However you have just started to get used to Textmate as an editor and you see it supports regex matching. Why though does it not use /s or /m for multi-line dot matching? The reason is that Textmate uses the Oniguruma regular expression library. Oniguruma requires switching to multi-line mode by using an extended group (?m:) so the dot matches the new line as well. So our pattern would be:
Essentially doing this turns multi-line on for the sub-expression, being some.+?stuff
Make sense? I thought not. Read on about Textmate Regex for more information.

Simon Pierre Desrosiers said,

February 12, 2011 @ 07:49

Yes, but (?m:someexpression) leaves you with an uncaptured group. You need to use (?m:(someexpression)) in order for someexpression to be assigned to a $n variable.

Rob said,

March 21, 2011 @ 20:07

Cool, thanks guys, I could have looked for that for a long time without this info

Brian said,

February 5, 2017 @ 05:52

This was very helpful! I had searched all over before I found this, clearly explaining why /m was not working for me.

RSS feed for comments on this post · TrackBack URI

Leave a Comment