From: yermej Date: 2008-01-11T05:45:11+09:00 Subject: Re: string extraction On Jan 10, 2:38 pm, Li Chen wrote: > Hi all, > > What is the Ruby way to extract a string like this? > > old_string="5'-AAAAAAAA    CCCCCCCC  TTT   GGGGG    GGGG-3'" > new_string="AAAAAAAACCCCCCCCTTTGGGGGGGGG" > > Thank you very much, > > Li > -- > Posted viahttp://www.ruby-forum.com/. new_string = old_string.gsub(/[^A-Z]/, '') That substitutes '' (empty string) for any character that is not (^) a capital letter (A-Z). To do the same thing in place: old_string.gsub!(/^A-Z]/, '')