Regex Generator
Create regular expression patterns with the free Regex Generator. Build expressions for common text matching, input validation, search and data extraction tasks. Test your pattern against sample text and review the matches before using it in your code or workflow. Regular expression syntax can vary between programming languages, so verify compatibility with your target engine.
Test a simple email-address pattern. Load the example to see the tool in action.
Checks for the shape name@domain.tld. It does not prove the address exists.
- Match: email@example.com
Each line of test text is checked on its own against the whole pattern. Always test patterns with your own data before using them for validation.
What is Regex Generator?
Build regular expression patterns with the free Regex Generator. Create expressions for common text matching, input validation, searching and data extraction tasks. Test patterns against sample text to review matches before using them in code or data-processing workflows. Because regular expression syntax differs between programming languages and engines, verify that your pattern works in the target environment.
Why use this tool?
- Start from a working pattern for email, URL, phone, date, IPv4, hex color, slug, username, ZIP code, UUID, password strength or decimal numbers.
- Edit the pattern and flags, then test it against your own sample text.
- Each line of test text is checked separately, so you can try many values at once.
- The output includes the pattern as a JavaScript literal and as a new RegExp call.
How to use Regex Generator
- Step 1. Choose a common pattern from the list.
- Step 2. Edit the pattern or flags if you need something different.
- Step 3. Enter test values, one per line, and check which lines match.
- Step 4. Copy the pattern into your code.
Common use cases
Use a regular expression to validate a slug
This example accepts lowercase letters, numbers, and single hyphens between groups.
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
console.log(slugPattern.test("online-json-tool")); // trueImportant notes
- Patterns are tested with JavaScript's regular expression engine. Other languages can differ in syntax and features.
- The g and y flags are ignored, so each line is tested once against the whole pattern.
- The patterns are starting points. The email pattern checks only the shape name@domain.tld and does not prove an address exists.
- Always validate important input on the server as well, and avoid nested quantifiers that can make a pattern very slow on long input.
More Code & Formatting Tools
Regex Generator FAQ
How do I validate an email address with regex?
Use a simple pattern such as ^[^\s@]+@[^\s@]+\.[^\s@]+$ to check the basic shape, then confirm the address by sending a message. Strict email patterns are long and still miss cases.
What do the flags mean?
i ignores case, m makes ^ and $ match at each line, s lets . match a new line, and u enables Unicode mode.
What is the difference between the Regex Generator and the Regex Tester?
The generator starts from common patterns for you to edit. The Regex Tester is for checking a pattern you already have against text.
Will these patterns work in Python or PHP?
Many of them will, because the syntax is common. Test them in your own language, since escaping rules and features can differ.