Hi --

On Thu, 13 Jul 2006, Seth Thomas Rasmussen wrote:

> Hi Daniel,
>
> Daniel Schierbeck wrote:
>> I'm trying to write a regular expression that matches bencoded strings,
>> i.e. strings on the form x:y, where x is the numeric length of y.
>>
>> This is valid:
>>
>>    6:foobar
>>
>> while this is not:
>>
>>    4:foo
>>
>> I've tried using #{$1} inside the regexp, but it seems $1 is still nil
>> at that point.
>
> I think you can do what you want there, but if you're using captures
> within the regex they are captured in, you denote them as \1, \2, etc.
>
> %r{<(foo)></\1>} # should match a pair of empty "foo" tags

It does, but the issue would be getting it to interpolate and be
pre-processed as a quantifier:

   /(\d):\w{#{\1}}/  or something

which doesn't seem to be possible, at least as far as I can tell.


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
http://www.manning.com/black     => RUBY FOR RAILS (reviewed on
                                     Slashdot, 7/12/2006!)
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
dblack / wobblini.net              => me