From: Stefano Crocco Date: 2008-01-11T06:38:51+09:00 Subject: Re: search pattern Alle giovedì 10 gennaio 2008, Li Chen ha scritto: > Hi all, > > I have a Ruby script as follow. What I try to do is to find a pattern in > the string and report its position. I wonder how to get the position of > pattern in the string. > > Thank you in advance, > > Li > > > > seq="5'aaaAAAAAACCCCCCCCTTTTTTTGGGGGGGGG-3'" > > seq.upcase!# change to upper case > puts "old sequence:" > puts seq.gsub!(/[^A-Z]/,'')# extract the string > puts pattern if seq=~/AC/ > > #how to get the position of pattern in the string? String=~ returns the position of the starting of the match, so seq=~pattern will return what you want. Stefano