Regex Cookbook and Tester
Write or pick a regular expression, see every match and capture group highlighted, and copy working code for JavaScript, Python, Java, C#, PHP and Go.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Choose a task
Test, browse or escape.
- 2Enter or pick a pattern
Your own or from the cookbook.
- 3Add flags
g, i, m, s, u or y.
- 4Paste test text
Matches highlight instantly.
- 5Read the groups
Each capture in the table.
- 6Copy the code
For your programming language.
About this tool
Regular expressions are compact and powerful, and easy to get subtly wrong. A date pattern that accepts month 13, an email pattern that rejects plus addressing, or a UK postcode pattern that allows impossible letters can sit in production code for years. This tool combines three things. The tester runs your pattern on sample text as you type, highlights each match, lists every capture group, including named groups, and warns about patterns that use features Go and RE2 lack or that risk catastrophic backtracking. The cookbook holds 62 patterns for common jobs, from integers, decimals and percentages to ISO dates, times, URLs, IPv4 and IPv6, MAC addresses, UK and Canadian postcodes, National Insurance numbers, UUIDs, semantic versions, E.164 phone numbers, hashtags, JWTs and leaked AWS keys. Every pattern is automatically tested against examples it must match and counter-examples it must reject, and both lists are shown. The escaper turns literal text into a safe pattern. For any pattern you get ready-to-paste code in six languages with the flags translated correctly.
Flags
- g: find all matches rather than the first. - i: ignore case. - m: make ^ and $ match at line breaks. - s: let the dot match line breaks too. - u: Unicode mode, needed for property escapes such as letters in any script. - y: sticky, match only at the current position.
Flavours differ
JavaScript, Python, Java, .NET and PHP (PCRE) share most syntax, but not all. Go, Rust's default regex crate and Google RE2 deliberately leave out lookarounds and backreferences so matching always runs in linear time; the tool warns when a pattern uses them. Python needs raw strings, Java needs every backslash doubled inside a string literal, and C# verbatim strings double quotes instead. The generated snippets handle these differences.
Validation versus searching
Anchors decide the job. A pattern between ^ and $ validates a whole field, while the same pattern without anchors searches inside longer text. Many cookbook entries are validators; remove the anchors and add the g flag to search.
Patterns are a first filter
Regular expressions check shape, not meaning. A date pattern cannot know that February has 28 or 29 days, an IBAN pattern cannot verify check digits, and an email pattern cannot prove a mailbox exists. Use the pattern to reject obvious mistakes, then validate properly in code.
Performance and safety
Nested quantifiers such as (a+)+ can take exponential time on carefully crafted input, a denial-of-service risk known as ReDoS. Keep patterns simple when they run on text from users, and set time limits where your platform allows.
Limits
The tester runs JavaScript regular expressions in your browser. Other flavours usually behave the same for these patterns, but test in your target language before relying on edge cases.
Worked example
Testing the default ISO date pattern with three capture groups on Invoice 2026-10-29, due 2026-11-28 finds two matches with three groups each, year, month and day, and the cookbook's UK postcode pattern accepts SW1A 1AA and EC1A1BB but rejects QQ1 1AA.
Quick facts
- Category: Developer & Data
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: ECMAScript regular expressions and the semver.org pattern
Frequently asked questions
Which regex flavour does the tester use?
JavaScript, the engine in your browser. Snippets are given for five other languages.
Are the cookbook patterns tested?
Yes. Each is checked automatically against matching and non-matching examples.
Why does my pattern fail in Go?
Go's RE2 engine does not support lookarounds or backreferences.
How do I match a literal dot or bracket?
Escape it with a backslash, or use the escaper to do it for you.
Can regex validate an email address fully?
No. It can check the shape; only sending a message proves the address works.
Is my text uploaded?
No. Matching runs in your browser.
