From: Logan Capaldo Date: 2006-07-13T02:21:30+09:00 Subject: Re: Help with a regexp On Jul 12, 2006, at 10:10 AM, 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. 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? > > > Cheers, > Daniel > I believe that this is not in the set of languages a Regexp can match. As others have already suggested you'll have to do it in 2 steps.