Regex Patterns Generator¶
The <key> element supports regex patterns to generate string data matching a specific format. Regular expressions (regex) define the allowed shape, and the generator produces strings that match the pattern.
Basic Syntax for Regex Patterns¶
To use a regex pattern in a <key> element, you specify the pattern attribute with the desired regular expression. Here is the basic syntax:
1 | |
Examples of Regex Patterns¶
Here are some examples showcasing different regex patterns and their uses:
- Alphabetic Strings
To generate strings consisting of only alphabetic characters with a length between 5 and 15 characters:
1 | |
This pattern matches any string that is between 5 and 15 characters long and contains only uppercase and lowercase letters.
- Numeric Strings
To generate strings consisting of only numeric characters with exactly 10 digits:
1 | |
This pattern matches any string that is exactly 10 digits long.
- Alphanumeric Strings
To generate strings that contain a mix of uppercase letters, lowercase letters, and digits, with a length between 8 and 12 characters:
1 | |
This pattern matches any string that is between 8 and 12 characters long and contains any combination of uppercase letters, lowercase letters, and digits.
- Email Addresses
To generate strings that resemble email addresses:
1 | |
This pattern matches typical email addresses, ensuring the string contains an "@" symbol and a domain.
- UUIDs
To generate strings that match the UUID format:
1 | |
This pattern matches UUIDs, ensuring the string follows the standard UUID format.
- Date Formats
To generate strings that match a specific date format (e.g., YYYY-MM-DD):
1 | |
This pattern matches dates in the format of four digits for the year, followed by a hyphen, two digits for the month, another hyphen, and two digits for the day.
Combining Patterns¶
You can also combine multiple patterns to create more complex constraints. For example, to generate strings that start with an uppercase letter, followed by lowercase letters, and end with a digit:
1 | |
This pattern ensures that the string starts with an uppercase letter, is followed by one or more lowercase letters, and ends with a digit.
Regex patterns let you constrain generated string data to a specific format — useful when downstream systems require structured identifiers, codes, or formatted values.