From: Michael Campbell Date: 2003-06-11T01:18:01+09:00 Subject: Re: OT: Regexp question --- Laurent Sansonetti wrote: > Hello Dominik, > > Dominik Werder wrote: > > This is probably not the easiest way to solve this: > > file.gets=~/(.+?)( \(.+)?$/ > > puts $1 > > > > How can I make it easier? > > > > laurent@bigmac ~> irb --simple-prompt > >> a = [ "Illinois (3762)", "Indiana", "Iowa (64)", "Kansas", > "Kentucky > (2675)" ] > => ["Illinois (3762)", "Indiana", "Iowa (64)", "Kansas", "Kentucky > (2675)"] > >> r = /(\w+)/ > => /(\w+)/ > >> a.each { |s| p r.match(s)[0] } > "Illinois" > "Indiana" > "Iowa" > "Kansas" > "Kentucky" > > Hope this helps, Add "South Dakota (00)", "New Jersey (29332)" to your tests... =) __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com