From: Phrogz Date: 2005-10-04T00:46:47+09:00 Subject: Re: String#scan_and_map (was: Re: split without lookbehind) > Following is my hackish attempt to make a String#scan_and_map > function that does the above. OK, that was dumb. On the way to work I realized that the above can far more correctly be implemented simply as: class String def scan_and_map( regexp ) results = [] scan( regexp ){ |args| results << yield( args ) } results end end str = 'foo,bar ,, baz,qux,,,jorb,jing,,,,blat' p str.scan_and_map( /(.+?[^,],{2}*)(?:,(?!,)|$)/ ){ |saved,others| saved } #=> ["foo", "bar , baz", "qux,", "jorb", "jing,,blat"]