Aleksi Niemelwrote: > >Ben asked: > > Well everything in it is going to be fairly easy to translate > > except the ability to loop over matches of an RE. > >Without having time to read your mail properly and analyze the code I'd >suggest two things: > > str = getSourceStr > re = /#{fairly_complex_re}/ > while matches = re.match(str) > have_fun_with(matches[1..-1]) > str = matches.post_match > end This is exactly what I said I did not consider acceptable because of the copying overhead. >There's also a dedicated C module to not do so much copying: It shouldn't require any copying. The functionality is available in plenty of other languages without needing that. > http://www.ruby-lang.org/en/raa-list.rhtml?name=strscan > >But another, easy way is to use String#scan: > > http://www.rubycentral.com/ref/ref_c_string.html#scan Between matches in the example I want to translate, I change which RE I am matching with. With the requested feature it would be trivial to create generalizations of scan that are efficient... >Disclaimer 2:) I might misunderstood your problem completely. You understand the effect I want, but haven't addressed the efficiency issue. Slightly faster, slightly slower I don't care about. O(n) vs O(n*n) when there is no real reason to be slow is a showstopper. Cheers, Ben _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com