From: Daniel Waite Date: 2007-10-31T08:33:05+09:00 Subject: Re: Why, oh, why, little regexp? Joel VanderWerf wrote: >> What I'd like is to grab all the "words" in the string. So in the above >> example I'd like two matches, cost and tax. >> >> Any ideas? > > 'cost * tax'.scan(/\w+/) > => ["cost", "tax"] How do you people do that? The last time I had a regexp question someone came down from the clouds and handed me something about that short. Why do I think it's more difficult than it is? After making the example a little more complex I had to change it every-so-slightly... 'cost * tax + 0.075'.scan(/[a-z]+/) => ["cost", "tax"] But it's effectively the same. Thank you Joel, you rock! Is there a book you recommend to learn more about regular expressions? How did YOU learn them? >> PS: match(...).captures always, always returns an empty array... > How are you using it? > > "foo".match(/(foo)/).captures > => ["foo"] > 'cost * tax'.match(/([a-z]+)*/).captures > => ["cost"] LOL I'm an idiot -- *captures* -- back references, right. Gotcha... -- Posted via http://www.ruby-forum.com/.