Test JavaScript Regular Expressions and Highlight Matches
Live Match PreviewA regular expression describes a text pattern, and small punctuation changes can completely alter the result. The Regex Tester uses the JavaScript RegExp engine built into your browser: enter pattern source without surrounding slash delimiters, choose the g, i, m, and s flags, and provide a test string. Matches are highlighted in the preview, and invalid patterns produce a syntax error. It is great for exploration and debugging, but it does not prove a regex is safe, efficient, portable to another language, or sufficient for security validation.
Quick answer. Enter only the pattern — not /pattern/g — then choose flags separately. Enable g to find every non-overlapping match. Test both expected matches and near misses, and avoid running untrusted or backtracking-heavy patterns against large input.
What this regex tester does
- • Compiles a pattern with JavaScript's
new RegExp(pattern, flags)constructor. - • Supports the
g,i,m, andsflags. - • Tests the expression against sample text and highlights matching substrings.
- • Counts matches and displays syntax errors from the browser's JavaScript engine.
- • Expands the test and preview areas as content grows, up to the current height limit.
It does not provide replacement templates, capture-group tables, code generation, flavor conversion, or a guarantee that the expression performs safely on arbitrary input.
Enter pattern source without slash delimiters
JavaScript source often displays a regex literal like /\b[A-Z][a-z]+\b/g. In the tester, enter only the pattern and enable the g flag separately:
\b[A-Z][a-z]+\b
The opening and closing slashes belong to JavaScript's regex-literal notation. They are not part of the pattern passed to the RegExp constructor, so if you include them the tool looks for literal slash characters around the match.
Supported JavaScript regex flags
| Flag | Name | Effect |
|---|---|---|
g | Global | Finds repeated non-overlapping matches instead of stopping after the first |
i | Case-insensitive | Ignores ordinary letter case distinctions during matching |
m | Multiline | Changes ^ and $ so they can match line boundaries within the test string |
s | DotAll | Allows . to match line-terminator characters |
The interface does not currently expose JavaScript's u, v, y, or d flags. Pattern behavior follows the features supported by the current browser.
How to test a regular expression
- 1. Define the exact matching goal. Write down what should match and what must not. "Find dates" is vague; "find ISO-style calendar dates written as YYYY-MM-DD in a log line" is a more useful requirement.
- 2. Enter the pattern. Provide pattern source without slash delimiters, starting with the smallest expression that captures the requirement, for example
\b\d{4}-\d{2}-\d{2}\b. This recognizes the shape of a date; it does not prove that2026-99-99is real. - 3. Select only the required flags. Enable
gwhen every occurrence matters,ionly when case should be ignored, andmorsbased on specific line-boundary behavior rather than enabling every flag by default. - 4. Add representative test text. Include expected matches, expected nonmatches, empty input, text at the beginning and end, multiple lines, punctuation next to matches, Unicode characters, very long values, and values that nearly match.
- 5. Review the highlighted output. With
g, the tool iterates through every non-overlapping match; withoutg, it highlights only the first. - 6. Test performance and portability. Before production, test in the actual runtime with realistic maximum input sizes. A browser result does not guarantee identical syntax or performance in Python, .NET, Java, PHP, Go, a database, or a CLI tool.
Core regex building blocks
- Literal characters: most characters match themselves;
catmatches those three letters. - Character classes: square brackets match one character from a set, e.g.
[A-F0-9]for one uppercase hex character. - Predefined classes:
\da digit,\wcommonly ASCII letters/digits/underscore,\swhitespace; uppercase forms like\Dmean the opposite. Do not assume\wcovers every writing system. - Quantifiers:
*zero or more,+one or more,?zero or one,{3}exactly three,{2,5}between two and five — applied to the immediately preceding token or group. - Groups: parentheses group and capture, e.g.
(red|green|blue); use(?:...)for grouping without capture. - Alternation: the pipe means "or", e.g.
cat|dog. - Anchors:
^start (or line start withm),$end (or line end withm),\ba word boundary. - Lookaround: modern engines can support lookahead and lookbehind, but verify browser compatibility and performance before relying on them.
Practical examples
| Goal | Pattern | Flags | Note |
|---|---|---|---|
| ISO-style date shapes | \b\d{4}-\d{2}-\d{2}\b | g | Formatting only; calendar validation needs extra logic |
| Repeated whitespace | [ \t]{2,} | g | Two or more spaces or tabs, not line breaks |
| Simple hex colors | #[0-9A-Fa-f]{6}\b | g | Six-digit only; not 3/4/8-digit variants |
| A complete simple identifier | ^[A-Za-z_][A-Za-z0-9_]*$ | none | Anchoring both ends checks the full string shape |
| Lines beginning with ERROR | ^ERROR\b.*$ | gm | The m flag lets ^ and $ apply to each line |
The global flag and non-overlapping matches
With g, the implementation repeatedly calls RegExp.exec() and continues from the end of the previous match, producing non-overlapping matches. For example, searching for aba in ababa finds the first aba; the second possible occurrence begins inside the first match, so ordinary global iteration does not return it.
Overlapping matches usually require lookahead or a different scanning strategy. Without g, the tool calls the regex once and highlights only the first match.
Zero-width matches
Some expressions can match a position without consuming characters — anchors, boundaries, and certain lookarounds. Repeatedly executing a global zero-width expression could otherwise loop forever because the regex ends where it began. The current implementation detects when the match index equals lastIndex and manually advances the index by one position.
Zero-width matches may not produce a visible highlighted region because no characters are part of the match. Use focused tests when exploring them.
Multiline and dotAll are different
Multiline (m)
Changes the meaning of ^ and $. It does not make dot match newline characters.
DotAll (s)
Allows . to include line terminators. It does not change the meaning of ^ or $.
An expression that should match complete lines may need m; one that should span across line breaks may need s. Some patterns need both, and many need neither.
JavaScript regex flavor and portability
Regular-expression engines share common syntax but are not identical. Differences can include supported flags, lookbehind support, named-capture syntax, Unicode properties, character-class behavior, backreferences, atomic groups, possessive quantifiers, conditional expressions, replacement syntax, and match-timeout support.
A pattern tested in JavaScript may fail to compile or behave differently in PCRE, Python, Java, .NET, Rust, Go, RE2, PostgreSQL, or another engine. Test the final expression in the actual environment where it will run.
Regex is not enough for every validation task
- • A date-shaped string may describe an impossible date.
- • An email-shaped string may not identify a working mailbox.
- • A URL-shaped string may point to an unsafe or nonexistent destination.
- • A number may fit the pattern but fall outside an allowed range.
- • A filename may match yet still be unsafe in the target operating system.
Regex can check textual shape, but it often cannot establish real-world validity by itself. Use a parser, domain-specific validator, allowlist, and application logic when the meaning matters.
Performance and catastrophic backtracking
Some backtracking regex engines can take extremely long on carefully chosen input. Nested ambiguous quantifiers are a common warning sign — a risky pattern shape is ^(a+)+$. On a long string of a characters followed by a nonmatching character, the engine may explore many groupings before failing.
This can cause a frozen browser tab, high CPU usage, slow server responses, and denial-of-service exposure when patterns or input are untrusted. Reduce ambiguity, avoid unnecessary nested quantifiers, cap input length, and consider a linear-time regex engine for attacker-controlled data. The tester does not provide a timeout or prove that an expression is safe from regular-expression denial of service.
Security warning for untrusted text
The current match preview constructs highlighted HTML from the test text and inserts it into the page. It does not apply a separate HTML-escaping or sanitization step to every part of that preview.
Do not paste untrusted text containing HTML or script-like markup into the tester. A safe production implementation should treat all test text as text nodes or escape it before constructing preview markup. This limitation is separate from regex compilation: a pattern can be valid while the displayed input still contains unsafe HTML.
Privacy and data handling
The pattern and test string are processed in browser memory and are not sent to WeConvertFiles for regex matching. The browser's JavaScript RegExp engine performs compilation and matching.
If a visitor consents to site analytics, separate usage information such as visits, clicks, device details, or tool interactions may be collected. Those analytics do not receive the pattern or test text entered into the matcher.
The local environment still matters. Browser extensions, malware, clipboard managers, screen recording, and shared devices can expose text independently of the tester. Avoid using real passwords, tokens, personal data, private logs, or confidential source material as regex examples.
Limitations
- • JavaScript regex flavor only, with only
g,i,m, andsflags exposed. - • Non-overlapping matching; no replacement mode; no capture-group result table.
- • No code-snippet generator and no automatic cross-language conversion.
- • No match timeout or performance guarantee.
- • No separate sanitization layer for previewed test text.
- • No proof that a pattern validates real-world meaning.
Troubleshooting
Invalid regular expression
Check unclosed parentheses or brackets, misplaced quantifiers, incomplete escapes, unsupported syntax, and features unavailable in the current browser.
Only the first match appears
Enable the global g flag to search for repeated non-overlapping matches.
The pattern searches for literal slashes
Remove surrounding /.../ delimiters. Enter only pattern source and choose flags separately.
^ and $ do not match every line
Enable m. Without it, anchors normally apply to the complete test string.
Dot does not cross a line break
Enable s, or use a character class designed to include line terminators.
An expected overlapping match is absent
Standard global iteration advances past the previous match. Use lookahead or another algorithm when overlapping occurrences are required.
The browser becomes slow or unresponsive
The pattern may cause excessive backtracking. Reduce input size, simplify ambiguous quantifiers, and close the tab if necessary.
Markup in the sample behaves like HTML
Do not use untrusted HTML-like input in the current preview. The implementation does not separately sanitize every preview fragment.
The pattern works here but fails in another language
Confirm the target engine's syntax, flags, escaping rules, Unicode behavior, and supported features.
Frequently asked questions
Should I include /pattern/g slash delimiters?
No. Enter only the pattern and select g separately.
Which regex engine does the tool use?
It uses the JavaScript RegExp engine in the current browser.
Which flags are supported?
The interface supports g, i, m, and s.
How do I find every match?
Enable the global g flag. Matches are non-overlapping.
Can it find overlapping matches?
Not through ordinary global iteration. Some overlapping cases can be expressed with lookahead; others need a different algorithm.
What does the multiline flag do?
It changes ^ and $ so they can match boundaries within a multiline string.
What does the dotAll flag do?
It allows dot to match line-terminator characters.
Can a regex freeze the browser?
Yes. Certain patterns can cause excessive backtracking on particular input, and the current tool does not enforce a match timeout.
Is a matching email or date guaranteed to be valid?
No. Regex can check textual shape, but real-world validity often requires parsing and domain-specific checks.
Is it safe to paste untrusted HTML into the test field?
No. The current preview does not apply a separate sanitization step to all displayed text. Use controlled plain-text samples.
Related tools
Diff Checker
Compare two text versions rather than matching a pattern.
JSON Formatter
Validate structured JSON syntax with a parser.
Case Converter
Transform text casing without regex replacement.
Related guides
QR Code Generator Guide
Generate high-quality custom QR Codes for any URL, text, or phone number instantly.
Word & Character Counter Guide
Live-updates word, character, and paragraph counts plus a reading-time estimate.
JSON Formatter / Validator Guide
Format, validate, beautify, and minify raw JSON string data dynamically.
Test your regular expression
Enter a pattern without slashes, pick the flags you need, and highlight matches against representative plain-text samples.
Use Regex Tester