Generate random strings that match any given JavaScript regular expression.
randexp.js is a JavaScript library that generates random strings based on a provided regular expression pattern. It enables developers to create test data, sample strings, or placeholder content that adheres to complex regex rules, making it useful for testing and prototyping. The library supports a wide range of regex features, including grouping, alternation, character sets, backreferences, and repetition quantifiers.
Developers and testers who need to generate synthetic data matching specific patterns, such as those working on unit testing, data mocking, or prototyping applications that require structured string inputs. It is particularly valuable for JavaScript and TypeScript projects where regex-based string generation is needed.
Developers choose randexp.js because it leverages the universal expressiveness of regular expressions to define string patterns, bridging the gap between specification and synthetic data generation. Its unique selling points include full regex support, customizable character ranges, seedable PRNG overrides for deterministic outputs, and a convenient syntax for direct regex literal usage.
Create random 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 grouping, alternation, character sets, backreferences, and more, as demonstrated with examples like /<([a-z]\w{0,20})>foo<\1>/ generating valid strings.
Allows modification of the default ASCII range via defaultRange.add/subtract, enabling Unicode support, as shown in the README with adding code points up to 65535.
Provides ability to override randInt for seedable or cryptographic PRNGs, ensuring reproducible outputs for testing, as detailed in the Custom PRNG section.
Offers shorthand .gen() on regex literals with sugar(), simplifying code usage, such as /yes|no|maybe/.gen() generating a random match.
Ignores regex positional tokens like ^ and $ in certain placements (e.g., /a^/), which may not align with real regex engine behavior and can lead to unexpected outputs.
For regex patterns that cannot match anything, such as /[^\w\W]/, it returns empty strings without clear error handling, potentially causing silent issues in data generation.
Infinite repetitions default to adding 100 to the min, requiring manual max property adjustment for different bounds, which adds overhead for fine-tuning string lengths.