From: david@... Date: 2005-08-01T21:56:04+09:00 Subject: Re: Chopping the beginning of a string elegantly Cit�t "francisrammeloo@hotmail.com" : > I'm sorry but my first post was misleading. > > The string actually looks like this: > > " BeginCaption 0, 20, 66, .." > (the whitespace can be a combination of tabs and spaces) > > So I actually have to cut out "Caption" word in the <> of the > string. > > Brian's hint got me on the right track. The solution I finally found > was: > > pane = line.sub(/\s*Begin(\w+).*/, '\1') > > Unless some expert can prove a still more tight solution I believe I > have found the best way to cut out the "Caption" part of the string. > > Thank you all for your help. > > Best regards, > Francis > > > Hmm. A wild guess (e.g. until there's a Windows installer for Ruby 1.9 w/ Oniguruma, or someone makes a SuSE compatible RPM for that) is that lookbehinds in REs could reduce that to: pane = line[/(?<=Begin)\w+/] There's a 95% chance you don't need those groups to catch the initial whitespace and consume the rest of the string, so: pane = line.match(/Begin(\w+)/)[1] also works and has a bit less noise. Weirdly though, Benchmark tells me it's slightly slower. Guess you can't have your cake and eat it. David (ikkle newbie and all that)