On Aug 2, 2006, at 12:21, Justin Collins wrote:

> Pavel Smerk wrote:
>>
>> But where can one find this feature of the split in the 
>> documentation? http://www.rubycentral.com/ref/ref_c_string.html#split 
>> does not mention split returns not only delimited substrings, but 
>> also successful groups from the match of the regexp.
>>
>> Regards,
>>
>> P.
>>
>
> As far as I can see, it's not in the documentation. I found it by 
> accident. But, yes, the scan method is better. :)

Oh, my gosh. If only you'd posted this little tidbit two days ago, I'd 
have saved a couple hours of code-wrangling.

For sorting purposes, I needed to turn something like
	one-and.two / three.net
into
	net.three / two.one-and

I started with str.split(/[.]|@/), but then I'd lose where the @ went. 
I tried turning it into
	["one-and", ".", "two", "@", "three", ".", "net"]
so I could .reverse that, but without positive look-behind, I couldn't 
find any way to detect the break *after* the dot except with \w, which 
would also trigger after the hyphen.

After hours of work, I ended up with something that was not only long 
and confusing, involving .collect and an inner search loop and other 
stuff, but when I brought it back up to check it for this email 
message, I discovered that it didn't even actually work correctly.

And all along, all I needed to do was change
	str.split(/[.]|@).reverse.join
into
	str.split(/([.]|@)/).reverse.join

Dang. And thanks! :)