From: Ne Scripter Date: 2009-10-21T16:52:58+09:00 Subject: Re: Complex GSUB query Thanks all. I went the suggestion given by David because although the structure is consistent I can never be sure on the number of elements in the string. Many thanks Rob Biedenharn wrote: > On Oct 20, 2009, at 11:37 AM, David A. Black wrote: > >>> I have a string like follows: >>> However the problem with doing this is that there are commas >> >> Compleat Jan 22-23, 2010, Tampa, FL >> Rubyist http://www.thecompleatrubyist.com >> >> David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com) > > Or perhaps scan is a better hammer for this nail: > > irb> string = "\"bloggs, Joe (JBloggs, INFO)\" joebloggs, \"bloggs, > Bill (BBloggs, INFO)\" billbloggs" > => "\"bloggs, Joe (JBloggs, INFO)\" joebloggs, \"bloggs, Bill > (BBloggs, INFO)\" billbloggs" > irb> re = %r{"\w+, \w+ \(\w+, \w+\)" \w+} > => /"\w+, \w+ \(\w+, \w+\)" \w+/ > irb> string.scan(re) > => ["\"bloggs, Joe (JBloggs, INFO)\" joebloggs", "\"bloggs, Bill > (BBloggs, INFO)\" billbloggs"] > > You could paste them back together with a .join('_'), but I suspect > that you want the pieces later anyway. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob@AgileConsultingLLC.com -- Posted via http://www.ruby-forum.com/.