From: "David A. Black" Date: 2008-12-18T07:22:18+09:00 Subject: Re: Hopefully simple regex Hi -- On Thu, 18 Dec 2008, stephen O'D wrote: > Hi, > > I am trying to make a regex that will capture strings that look like > '@string' surrounded by whitespace or at the start or end of a line - > here is the spec: > > > require 'test/unit' > > class RegexTest < Test::Unit::TestCase > > def setup > # this doesn't work correctly for the fails scenarios > @regex = /(@{1,1}\w+)/ > end > > I have tried all sorts of combinations of character class and negated > classes etc until my eyes have started glazing over - I really though > this should be easy - can anyone suggest a regex that pass my spec > above? Try this: @regex = /(?:^|\s)(@\w+)/ David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)