Re: Help with a regexp

Daniel,

here’s a function to do what you want …

class String
def bencode?
if /^([1-9]+\d*):/.match(self)==nil
return false
else
number=eval((/(^([1-9]+\d*)):/.match(self))[1])
rest_of_string_length=self[self.index(’:’)+1…-1].length
if number==rest_of_string_length
return true
else
return false
end
end
end
end

Best regards,

Axel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs