From: Joel VanderWerf Date: 2005-08-14T13:03:27+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". You just have to tinker with the pattern a bit: "astring"[/.*?(?=r)/] # ==> "ast" "astring"[/ast(.*)/, 1] # ==> "ring" The (?=r) is a lookahead operator that matches but does not consume characters. The numerical argument n=1 in the second example indicates that #[] should return the value of the n-th capture -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407