From: "studlee2@..." Date: 2006-07-13T02:05:05+09:00 Subject: Re: Help with a regexp Daniel, When you grab the data it will be in a string format, so you need to convert it to a number (most likely integer). Then you can compare it with the size of the second value you grabbed. I would write it like this (modify as needed): print "enter data" a = gets valid = /^(\d*):(\w*)/ check = valid.match(a) if(check[1].to_i == check[2].size) end I hope this helps. _Steve 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