From: dblack@... Date: 2007-08-06T11:00:18+09:00 Subject: Re: Doubts on char patterns into String.each argument Hi -- On Mon, 6 Aug 2007, Ken Bloom wrote: > On Mon, 06 Aug 2007 08:43:07 +0900, Carlos Ortega wrote: > >> "Substring1 Substring2 Substring3".each( '\s*' ) { | substring | >> puts "[" + substring +"]" >> } > > In ruby, if you want something to be interpreted as a regular expression, > you must declare it as a regular expression. Hence /\s*/ would be > correct. Except that each() only accepts strings, so you can't use a > regular expression with it. > > Use > "Substring1 Substring2 Substring3".split(/\s+/).each{|x| puts x} > instead You could also just do: puts "Substring1 Substring2 Substring3".split(' ') You could even leave off the (' '), except then if $; has a value you'd end up splitting on that. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)