Regexp Replace

ruby

Fri Apr 03 18:57:08 -0700 2009

My favorite feature of Ruby’s gsub is the ability to pass a block:

"1|2|3".gsub(/\d/) { |m| m.to_i+1 }    # => "2|3|4"

This is all kinds of useful.