A Ruby gem that generates example strings matching any given regular expression, including random examples.
regexp-examples is a Ruby library that extends the Regexp class to generate strings matching any given regular expression. It solves the problem of understanding and testing regex patterns by producing concrete examples, including exhaustive lists and random samples. This helps developers verify regex behavior, debug edge cases, and create test data efficiently.
Ruby developers working with regular expressions for validation, parsing, or text processing who need to test, debug, or demonstrate regex patterns. It's particularly useful for QA engineers, educators, and anyone building regex-heavy applications.
Developers choose regexp-examples for its comprehensive regex support, configurability, and ability to generate both exhaustive and random examples. Its unique selling point is the reverse-engineering of regex patterns into tangible strings, bridging the gap between abstract patterns and real-world matches.
Generate strings that match a given regular expression
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Handles a wide range of regex features including quantifiers, character sets, Unicode, named properties, and even backreferences, as shown in the README with examples like /\p{Greek}{80}/ and /(this|that) \1/.
Offers adjustable parameters like max_repeater_variance and max_results_limit to control output size and performance, allowing customization for different testing scenarios, such as generating all 1-5 digit strings.
Provides both exhaustive (Regexp#examples) and random (Regexp#random_example) string generation, useful for comprehensive validation and fuzz testing, as demonstrated with examples like /a*/.examples and /\w{10}@(hotmail|gmail)\.com/.random_example.
Configuration can be applied globally, per block, or per call without thread conflicts, ensuring safe use in multi-threaded environments, as noted in the configuration section.
Cannot handle non-regular features like lookarounds, subexpression calls, and most anchors, raising IllegalSyntax exceptions for these patterns, which limits advanced regex testing.
Only supports MRI Ruby 2.4.0 to 3.0.0, with dropped support for older versions and untested compatibility on alternatives like JRuby, potentially restricting its use in diverse environments.
For regexes with infinite or huge match sets, exhaustive generation is capped by max_results_limit (default 10000), so it doesn't provide truly complete examples and may miss edge cases.