如何通过 ruby 中给定的正则表达式生成字符串?
Class MyRegex
def self.generate_string(reg)
#return generated string.
end
end
当我打电话时
MyRegex.generate_string(/a*/) #it will return random string.
预期输出:
aaa
aa
aaaaa
等等
最佳答案
来晚了一点,但我已经创建了一个强大的 ruby gem ,它解决了最初的问题:
https://github.com/tom-lord/regexp-examples
/this|is|awesome/.examples #=> ['this', 'is', 'awesome']
/https?:\/\/(www\.)?github\.com/.examples #=> ['http://github.com', 'http://www.github.com', 'https://github.com', 'https://www.github.com']
关于ruby - 通过给定的正则表达式生成字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22251342/