Regex Tester
Contact us at hello@vectobox.com or support@example.org. Visit https://vectobox.com/tools for more info. UUID: 550e8400-e29b-41d4-a716-446655440000 IP: 192.168.1.1, 10.0.0.255 Phone: +1-415-555-0132
- #1 at 14Length 18
- hello@vectobox.com
- #2 at 36Length 19
- support@example.org
Regex cheat sheet
\d digit \w word char \s whitespace [abc] any of a, b, c [^abc] none of a, b, c . any char (except newline)
^ start of line/string $ end of line/string \b word boundary \B non-word boundary
* 0 or more
+ 1 or more
? 0 or 1
{n} exactly n
{n,m} n to m
+? lazy(abc) capture group (?:abc) non-capturing (?<name>abc) named group | alternation \1 backreference
What this regex tester does
This page runs a regular expression against your text as you type. Matches are highlighted, listed with their start index and length, and split into numbered and named capture groups. Matching uses your browser's JavaScript RegExp engine, so results are what new RegExp() and String.prototype.matchAll() return in that browser. Use it to check a pattern before putting it in JavaScript code, a validation rule or an editor search.
Testing a pattern
- Type the pattern into Pattern without slashes: \d+, not /\d+/. The page opens with the Email preset and sample text loaded.
- Toggle the g, i, m, s, u and y flag chips in the toolbar. The active flags appear after the pattern, for example /gi.
- Paste text into Test text. Clear empties both fields; Try an example restores the sample.
- Read the highlighted Matches pane and Match details, which list each match's index and its $1, $2 … and named groups.
- Click a preset under Try (Email, URL, UUID, Phone, IPv4) to load a starting pattern. Copy matches copies all matched strings, one per line.
How matching is done
The pattern and flags go to new RegExp(pattern, flags). If the browser rejects the pattern, the page shows an error with the browser's error message, such as "Invalid group" or "Nothing to repeat".
Matches are collected with matchAll(), which requires the g flag, so the tool always adds g and every match is listed even when the g chip is off. With y on, each match must start where the previous one ended, beginning at index 0. Indexes and lengths are counted in UTF-16 code units, so most emoji count as 2.
Differences from PCRE and Python: JavaScript supports lookbehind, including variable-length lookbehind that Python's re module rejects, and named groups written (?<name>…). It has no possessive quantifiers (a++), atomic groups, recursion, leading inline flags such as (?i), or (?P<name>…) syntax. \d and \w match ASCII only, even with u, while Python 3 matches Unicode digits and letters. Without m, $ matches only at the very end of the text; in PCRE and Python it also matches before a final newline.
Worked example: extracting dates with named groups
Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}), no extra flags. Test text: Released 2024-03-15, patched 2024-11-02.
Scanning from the left, the engine first matches 2024-03-15 at index 9 (length 10), resumes at index 19 and matches 2024-11-02 at index 29.
The Matches list shows 2 matches: #1 @ 9 with year: 2024, month: 03, day: 15 (also shown as $1, $2, $3), and #2 @ 29 with year: 2024, month: 11, day: 02. In code these values are match.groups.year and so on, or $<year> in a replace() string.
Limits of this tester
- Zero-length matches are not listed. On the text baaac, a* lists only aaa; patterns such as ^ or \b alone list nothing.
- There is no single-match mode, no replace or split preview, and no d or v flag.
- An unmatched capture group and a group that matched an empty string both display as (empty).
- Matching runs on the main thread on every keystroke. Catastrophic backtracking, such as (a+)+$ on a long run of a's followed by another character, can freeze the tab.
- Presets are approximations, not validators. The Email pattern does not implement RFC 5322, and the unanchored IPv4 pattern matches 234.1.1.1 inside 1234.1.1.1.
Regex questions
Why does a pattern from Python or PCRE fail with an error?
It probably uses (?P<name>…), possessive quantifiers, atomic groups or a leading (?i). Write (?<name>…) and use the i chip. Note that \A and \Z are not anchors in JavaScript: without u they silently match the letters A and Z. Use ^ and $ instead.
What is the difference between the m and s flags?
m makes ^ and $ match at the start and end of every line. s makes . match line terminators such as \n, which it otherwise skips. They can be combined.
When do I need the u flag?
For property escapes such as \p{L} or \p{Script=Han}, for code point escapes such as \u{1F600}, and to treat an emoji as one character. It also makes syntax stricter: an unnecessary escape such as \a becomes an error.
What does the sticky flag change?
Each match must begin exactly where the previous one ended. On 12a3, \d with y finds 1 and 2 and stops at a; without y it finds 1, 2 and 3.
How do I match Chinese characters or other non-English letters?
The common range [\u4e00-\u9fa5] works without flags and covers U+4E00 to U+9FA5, but it misses characters added later (U+9FA6–U+9FFF) and the extension blocks. With the u flag on, \p{Script=Han} matches every Han character and \p{L} matches a letter in any script. \w matches neither, and Chinese punctuation is not part of Han.
What regex matches an email address or a phone number?
The Email preset uses [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}, which accepts ordinary addresses but does not implement RFC 5322. To check a whole input rather than find addresses inside text, wrap it in ^ and $. Phone formats differ by country; the Phone preset is a loose pattern for finding numbers, so validate against your country's numbering format instead.
Related tools
Related articles
- JavaScript Regex Flags and Capture Groups Explained
Build, debug, and learn regular expressions in the browser. We cover JS RegExp syntax, flags, capture groups, and the most common pitfalls.
- How to Read and Write Cron Expressions (5-Field POSIX)
Learn how to read, write, and debug 5-field POSIX cron expressions with a visual builder, plain-English explanations, and a live preview of the next runs.