Regex Generator
Build a regular expression from tested patterns, with anchors and flags, and try it against sample text.
Processing: This tool runs entirely in your browser. Your input and any file you open stay on your device — nothing is uploaded to a server.
How to use the regex generator
- Pick a starting pattern, or type your own.
- Add anchors and flags, reading what each one does.
- Test against your own text and check the matches are what you expect.
About this tool
Most regex problems start with copying an answer that was never checked. This starts from patterns that are already correct rather than from an empty box. Each preset is tested against its own example, and the notes say where each one stops being reliable — which is the part copied answers leave out.
The email pattern is deliberately permissive, and that is the considered choice rather than laziness. The official grammar allows quoted local parts, comments and forms no validator on the web accepts, so the strict patterns that circulate reject addresses belonging to real people. Nothing short of sending a message proves an address works, so matching loosely and confirming by email is the honest approach.
The IPv4 pattern is properly bounded, so `999.1.1.1` does not match. The short version everyone copies accepts any three digits per group, which means it validates addresses that cannot exist. The UUID pattern checks the version and variant nibbles rather than just the shape, so a random hex string of the right length is rejected.
Anchors and flags are offered with what each actually does, because two of them cause most of the confusion. Without the `s` flag a dot never matches a newline, which is why a pattern that works on one line fails on a paragraph. And `^` and `$` mean the ends of the string until `m` is set, at which point they mean the ends of each line.
One pattern is included as a warning: the HTML tag matcher works for finding tags and is the wrong tool for parsing HTML, where nesting and comments defeat any regular expression.
Common uses
- Getting a correct email or URL pattern without trusting a copied answer.
- Building a validation pattern and checking it against real examples.
- Learning what a flag changes by watching the matches change.
Frequently asked questions
- Why is the email pattern so loose?
- Because strict ones reject valid addresses. The specification allows forms no validator accepts, and the only real proof an address works is sending to it, so matching loosely and confirming by email is the honest approach.
- Why does my pattern not match across lines?
- A dot does not match a newline unless the s flag is set. That single flag explains most patterns that work on one line and fail on a paragraph.
- Can I parse HTML with a regular expression?
- Not reliably. Finding tags is fine; parsing is not, because nesting and comments are beyond what a regular expression can express. Use a parser.
Related tools
Regex Tester
Test a regular expression against sample text with live highlighting and capture groups.
Regex Explainer
Break a regular expression into pieces and explain what each one does in plain English.
Regex Escape
Escape text so it is treated as a literal inside a regular expression.
Regex Match Extractor
Pull every match out of text, with capture groups, named groups and positions.