# Re: Help with a regexp

**URL:** <https://www.ruby-forum.com/t/re-help-with-a-regexp/98106>\
**Category:** Ruby\
**Created:** [July 12, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/re-help-with-a-regexp/98106 "2006-07-12T16:30:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/re-help-with-a-regexp/98106/1 "2006-07-12T16:30:12Z")

</div>

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
