From: Andrew Johnson Date: 2006-01-25T16:13:13+09:00 Subject: Re: subsequence regular expression On Wed, 25 Jan 2006 15:07:31 +0900, diz rael wrote: [snip] > Anyway, I tried the following: > > s=3D~/.+?(ba)+/ > $& =3D> "5b300ba" > > It so happens that a "ba" was created on the stack, so > the regexp thinks it ends there, when in fact the > string I want it to return is: > 5b300ba00260 Well, you could just check for 2 or more 'ba' sequences: s =~ /(.*?)(ba){2,}/ p $1 but of course, your "dirty portion" just might just have two, or even more, stray 'ba' in a row -- so I suspect you want to grab everything from the beginning up to the longest subsequence of repeated 'ba's? One way: s = "5bbaba300ba00260babababababababababababa000bd1007b810ba92" puts s[0,s.index(s.scan(/(?:ba)+/).max)] But I may well be missing an easier way :-) cheers, andrew -- Andrew L. Johnson http://www.siaris.net/ The generation of random numbers is too important to be left to chance.