Latest: Genstatic, my first sip of coffee

Content with Style

Web Technique

Textmate search & reg exp

by Pascal Opitz on September 17 2008, 11:53

One of the nicest things about Textmate is the that you keep discovering things even after a year of using it. The project wide search and replace functionality already helped me, but I kept ignoring that little check box saying “Regular expression”.

Of course, for someone that quite likes regular expressions, using search and replace with regular expression matches is a very powerful I gave it a try, fired up the project wide search (cmd+shift+F) and changed CSS file names in various locations and folders by searching for

href=”(.+)foo.css”

, then replaced it with

href=”$1bar.css”

and, after double checking for what it did, just clicked on File->Save All (alt+cmd+S).

Very powerful, very neat!
One thing that I am still missing, though, is the muti-line search and replace field found in BBEdit or Homesite, which comes in handy when searching for whole blocks of HTML. Dealing with line breaks in the Textmate search is just too fiddly, and maybe there’s a better way but I haven’t found it yet?

Comments

  • When you pull up the Find & Replace window, try pressing the icon with the down arrow on it. This will expand both text fields so you can enter multiple lines.

    by Elliot Winkler on October 22 2008, 01:25 - #

  • Elliot, you’ve just become my hero of the week! So obvious, and I do wear glasses with Carl Zeiss lenses, so I really should be able to see that, no?

    by Pascal Opitz on October 22 2008, 02:16 - #

  • http://techdebug.com/blog/category/regex/

    I thought it couldn't be done either, then I found out it was due to the Oniguruma style of regex that is used.

    by Gavin on June 13 2009, 16:57 - #


Comments for this article are closed.