Archive for July, 2006

Ravenous Regex

Sunday, July 30th, 2006

I like ViM. No… I love ViM. No… my fingers love ViM, and my brain doesn’t know it.

One thing I really like about ViM, is that after 10 years, I still learn new things. For example, today I learned how to construct non-greedy regex.

For one of my consulting gigs, I’m migrating a decent sized website into the rails framework. In doing so, I’m also converting (to the best of my ability and time) the site to use as much CSS as possible. Thus, gone are things like <font…> tags. The problem is trying to glob out the attributes of the font tag. How do you match <font size=”12px” color=”#ebeb1d”>? One might try “%s/<font.*>//g“. The problem with the ViM regex, is that the final > doesn’t get matched… rather, the regex is greedy, skips the intended > and magically find a > further on down the path. So how do you disable the “greediness” ?

The trick is to prefix the intended > with “.\{-0,\}”. (that’s a zero)

Here’s the actual ViM example that will match <font…..>:

:%s/<font.\{-0,\}>//g

I agree that the keystrokes are a bit insane but (a) it works and (b) it works. enjoy!

Published!

Tuesday, July 25th, 2006

Checkout my latest publication in CM Journal. If you are a programmer and modify opensource code or fork internal projects, you’ll be happy to hear that tracking your changes is much easier with a Stream-based SCM model compared to a traditional Branch-based SCM model. If you’ve been using branch-based tools like CVS or Subversion, thinking in streams (eg. AccuRev) will require you to switch SCM paradigms but it’s a fun and refreshing approach to a old problem.

I just got back from two weeks of non-stop travel…. CA –> Seattle –> CA –> Boston –> Chicago –> Denver –> CA. The trips to Seattle and Boston were for work, but Chicago was for total play. On the first night in Chicago, I met up with a great group of friends at the Double Door to hear our friend’s band Dummy. On the second night, my groomsmen and I donned sport coats and ties for some scotch, cigars, and steaks at the Racquet Club. I spent two afternoons skating Oak Street Beach and a sunday afternoon swimming with family at my Sister’s home in Libertyville. Finally, the weekend was topped off drinking some beers with my Best Man on his roof top while listening to the sounds of the Southport neighborhood festival. It was a fun two weeks of travel but I’m glad to be back home in California with Amy.