Robert Klemme wrote:
> 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
>
>
I should have added this - as it was puzzling me and I just now "got it" 
(and no one mentioned it) - for those who might be following along or 
will come after: the "\1" business isn't regex. That's why I could find 
nothing about it in my regex sources! It's a String#gsub() convention, 
and is documented there.

OK...all darkness is vanquished. For now. (!) ~t.

-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc / tomcloyd.com >> (email)
<< TomCloyd.com >> (website) 
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~