From: Hooopo Date: 2009-06-21T18:00:08+09:00 Subject: Re: regular expression gurus--help! On Jun 21, 4:08 pm, Harry Kakueki wrote: > On Sun, Jun 21, 2009 at 4:10 PM, timr wrote: > > I want all possible three letter sets for a string. Scan does this: > > irb> > > > But I need: > > # >> abc > > # >> bcd > > # >> cde > > # >> def > > etc. > > > I used to know the secret spell, but forgot it. Does anyone know how > > to do this with regular expression > > Here is one way to get that result. > (But not with a regular expression) > Not all 3 letter sets but I think this is the result you are really looking for. > > str = "abcdefghijkl" > puts str.unpack("a3X2"*(str.length-2)) > > #output > abc > bcd > cde > def > efg > fgh > ghi > hij > ijk > jkl > > Harry > > -- > A Look into Japanese Ruby List in Englishhttp://www.kakueki.com/ruby/list.html require'enumerator' "qwertyuiopasdfgd".scan(/./).each_cons(3){|x,y,z| p [x,y,z].join} "qwe" "wer" "ert" "rty" "tyu" "yui" "uio" "iop" "opa" "pas" "asd" "sdf" "dfg" "fgd"