by tom-lord · 11y ago · 0 comments
/this|is|awesome/.examples # => ["this", "is", "awesome"]
So, I tried it out on this "prime number validator" regex: /1?|(11+?)\1+/.examples
#=> ["", "1", "1111", "111111", "11111111"]
/1?|(11+?)\1+/.examples(max_repeater_variance: 50, max_group_results: 100).uniq.sort.map(&:length).first(10)
#=> [0, 1, 4, 6, 8, 9, 10, 12, 14, 15]
require 'prime'
Array(1..100) - /1?|(11+?)\1+/.examples(max_repeater_variance: 50, max_group_results: 3000).uniq.sort.map(&:length) == Prime.first(25)
#=> true
Horribly inefficient, but pretty cool! Here's my gem if case anyone's interested: https://github.com/tom-lord/regexp-examplesVery usefull!
It's still "under development", while I add a few missing features, but as you can see from the README these are only for fairly obscure parts of the regex language! - E.g. POSIX groups, named properties, character set intersection, ...