Sunday, September 6, 2009

Ruby regular expression

I'm not a regular expression expert nor am I a fan of its cryptic syntaxes. Nevertheless it's a useful tool to have in your programming toolbox

# String to match
message = "3798536196 Sun 10:02pm Jason Ong jasonong: @nazroll Dude, any possibility of some Wave action via uStream on that day? :) "

# Match sequence
message =~ /[\s]?[\w]+:[\s]/

# String with matches highlighted
3798536196 Sun 10:02pm Jason Ong jasonong: @nazroll Dude, any possibility of some Wave action via uStream on that day? :)

A good place to test out your ruby regex dynamically is http://rubular.com/

A ruby cheatsheet with good regex reference. http://www.zenspider.com/Languages/Ruby/QuickRef.html

No comments:

Blog Archive