From: Vance Heron Date: 2005-08-14T16:34:43+09:00 Subject: Re: YANQ (yet another newbie question): "string"[0.."e"] basi wrote: >Hello, > >Is there a way to say in Ruby: > >"astring"[0../r/] #"ast" >"astring"[/ast/..-1] #"ring" > >In other words, indexing using a "pattern". > >Thanks, >basi > > I can't do it with a literal string, but think this is close. irb(main):004:0> irb irb#1(main):001:0> s = 'astring' => "astring" irb#1(main):002:0> s[0..s.index('r')] => "astr" irb#1(main):003:0> s[s.index('ast')..-1] => "astring" irb#1(main):004:0> s[s.index('rin')..-1] => "ring" Note that the index for 'ast' is really 0, so [/ast/..-1] turns into [0..-1]. HTH, Vance