From: Pit Capitain Date: 2006-07-13T01:39:21+09:00 Subject: Re: Help with a regexp Daniel Schierbeck schrieb: > 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. Here's what I've got so far: > > /^([1-9]+\d*):(\w){#{$1}}$/ > > (it ain't working) > > I'm matching with `string =~ regexp'; would it be better if I did it > another way? Daniel, I'm pretty sure you can't do it with a single regexp test. Why not split the test in two parts, as in str =~ /^([1-9]\d*):(\w+)$/ && $2.size == $1.to_i Regards, Pit