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
>
>
David, badboy, Robert - thats to you all for the very clear 
explanations. I really couldn't find info. about this (yet). It IS 
clear, once the explanation's in had. I have to say that regex's 
becoming rather fun, now that I'm getting a little control of it.

I continue to be amazed at the generosity of this list in helping the 
real amateurs here move things along. We get that AND we get to listen 
in on all sorts of amazing and mysterious discussions of higher order 
magic. Pretty cool.

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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~