On 07.02.2009 21:50, Tom Cloyd wrote:
> That's beautifully economical, and reveals a far better grasp of regex 
> than I was able to attain last night. However, I'm having trouble with 
> this line:
> 
> data.gsub!(/<(h[1-6])>/, "\\1. ")
> 
> It certain works, but I don't grasp the "\\1. " part. I haven't yet 
> found anything that might shed light on this magic. How does it retain 
> the 'h' and whatever digit follows it? It looks somehow like "\\" == 
> retain matched alpha, and the "1" does the same for matched digits, but 
> I really haven't a clue. Can you elucidate just a bit?

The keyword is "capturing groups".  Brackets in the regexp denote groups 
of characters which can be referenced later via their numeric index as 
you have seen.  You can even use them for matching repetitions

/(fo+)\1/ =~ s # will match "fofo", "foofoo", "fooofooo" etc.

Cheers

	robert