开发者

Converting a regular expression to a string in Ruby

开发者 https://www.devze.com 2022-12-15 17:19 出处:网络
Is there a way of generating a string that would match a regular expression in Ruby e.g. regexoutput ^\\d{6}开发者_高级运维$875914

Is there a way of generating a string that would match a regular expression in Ruby

e.g.

regex           output
^\d{6}开发者_高级运维$         875914
^\d{3}-\w{2}    584-AS


From a response on a related SO question - Matt Aimonetti's randexp might be of some use. Not generalised to all regexp though...

EDIT: This version looks more up-to-date.


I haven't tested it, but this looks like something you're looking for: http://code.google.com/p/xeger/

Note that I cannot believe it will handle more complex regex-es (using look-arounds, back-references, etc.). But again, I haven't tested it.

EDIT: sorry, I now just saw you're looking for a Ruby implementation...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号