Regex Tester
Test JavaScript regex patterns against sample text with flags, match positions, capture groups, replacement preview, warnings, and JSON review before reuse.{{ summaryTitle }}
| Metric | Value | Copy |
|---|---|---|
| {{ row.metric }} | {{ row.value }} |
| # | Match | Index | Line:Col | Copy |
|---|---|---|---|---|
| No matches for the current pattern and sample. | ||||
| {{ row.number }} | {{ row.match }} | {{ row.index }}-{{ row.end }} | {{ row.line }}:{{ row.column }} | |
| Match | Group | Name | Value | Copy |
|---|---|---|---|---|
| No capturing groups participated in the current match set. | ||||
| {{ row.matchNumber }} | {{ row.group }} | {{ row.name }} | {{ row.value }} | |
{{ replacementText }}
Introduction:
A regular expression, or regex, is a compact rule for finding text that follows a pattern. It can pick names out of prose, locate IDs in logs, check whether a field contains a valid-looking token, or prepare a controlled text replacement. Small changes matter because a single flag, boundary, group, or quantifier can change how much text is found.
Regex testing is most useful when the sample text resembles the material that will later be searched, cleaned, or validated. A short sentence can prove that a capture group works. A log excerpt can reveal whether line anchors behave as expected. A large pasted file can show whether the expression is too broad before it is reused in code, a spreadsheet cleanup step, or an incident review.
A regex result should be read as evidence about the chosen pattern, flags, and sample, not as proof that the expression is safe for every future input. Overmatching can hide inside a longer string, non-global matching can stop after the first hit, and slow backtracking can appear only on larger or more hostile text. Good regex review pairs a realistic sample with explicit attention to matches, capture groups, replacement output, and warnings.
Replacement preview is especially useful because a pattern can find the right text while still producing the wrong rewritten text. Numbered and named captures, a literal dollar sign, and the full-match token all have special replacement meanings in JavaScript, so the preview should be checked before the replacement string is copied into another workflow.
Technical Details:
JavaScript regular expressions are created from a pattern string and a flag string. The pattern supplies the matching rule, while flags alter how the engine scans text, treats case, reads line anchors, handles Unicode, and records repeated matches. The same pattern can therefore return one match, many matches, no matches, or a compile error depending on the selected flags and the browser's RegExp support.
Match location is measured by zero-based character index inside the tested sample, while line and column positions are easier for people to use when checking prose or logs. Capturing groups add a second set of evidence: each group can participate, fail to participate, receive a numeric group number, and sometimes receive a group name. The d flag matters when start and end indices for captures are needed.
Rule Core:
| Rule | Behavior | Reader impact |
|---|---|---|
| Pattern entry | The regex is written as JavaScript RegExp syntax without surrounding slash delimiters. | Escapes, named groups, lookarounds, and character classes must be valid for the browser's JavaScript engine. |
| Flag normalization | Supported flags are ordered as d, g, i, m, s, u, v, and y; duplicates are removed. |
The summary badge shows the effective flag set, so a mixed or repeated entry still resolves to one clear flag string. |
| Unicode flags | u and v cannot be combined. |
Choosing both is a compile-time flag error rather than a partial test. |
| Repeated matching | g or y uses repeated exec calls; without those flags, JavaScript returns only the first match. |
A single hit can be correct for validation, but it is not a full inventory of every occurrence. |
| Zero-width matches | A match that consumes no characters is marked separately and advances one code unit before the next repeated check. | Boundary patterns such as \b or anchors can be inspected without trapping the scan. |
| Replacement preview | The replacement string follows JavaScript replacement syntax, including $&, $1, $2, $<name>, and $$. |
The rewritten text may differ from the match list when captures or dollar tokens are used. |
Large or risky test runs are bounded so the browser stays usable. The sample is limited before matching, the match ledger is capped, and the expression runs in a worker with a millisecond timeout. These limits do not prove that a regex is fast in every environment, but they make slow or overly broad patterns visible during review.
Guardrails And Result Limits:
| Control or cue | Minimum | Maximum | Effect |
|---|---|---|---|
| Match cap | 1 match | 2,000 matches | Stops the stored match list and export rows after the selected cap. |
| Execution timeout | 50 ms | 5,000 ms | Stops the worker when the expression does not finish in time. |
| Sample limit | 1,000 chars | 500,000 chars | Only the first selected number of characters is tested when the sample is longer. |
| Browse or drop file | 0 bytes | 4 MB | Text files over the file-size limit are rejected before reading. |
| Warnings | 0 | varies | Notes appear for truncation, capped listings, first-match-only runs, capture indices without d, and zero-width matches. |
Regular expression denial of service risk comes from patterns that require excessive backtracking on difficult inputs. A timeout or repeated slow run is a warning to simplify nested repetition, reduce overlapping alternatives, narrow the input, or test the pattern in the same runtime where it will be used.
Everyday Use & Decision Guide:
Start with a pattern that matches one real example, then add the smallest flag set that makes the result meaningful. The default sample uses names in sentences, which is useful for seeing named captures, global matching, and match positions. For a log or CSV review, paste the real excerpt or load a text-like file so line and column positions point back to the material you are actually checking.
Use Match Preview for a fast visual scan, then confirm the details in Match Ledger and Capture Groups. A highlighted preview is helpful, but it can hide why a later automation step failed. The ledger gives start and end indexes plus line and column, and the capture table shows whether the expected group value participated.
- Keep Pattern without leading and trailing slashes, such as
\b(?<word>[A-Z][a-z]+)\b. - Turn on
gwhen you need every non-overlapping match, not just the first hit. - Turn on
dwhen capture start and end positions matter for review. - Use Replacement with JavaScript tokens such as
$&,$1, or$<word>, then inspect Replacement Text. - Leave Execution timeout low while testing unknown patterns; raise it only for trusted expressions and controlled samples.
- Check Warnings before copying results, especially when the sample was truncated or the match list hit the cap.
A no-match result does not always mean the pattern is wrong. It can also mean the wrong flag set was used, the sample was truncated before the relevant text, or the expression is not global and only the first match was collected. Compare the summary badge, sample-size badge, and warning notes before changing the regex itself.
Step-by-Step Guide:
Use the tester to run a JavaScript regex against pasted or loaded sample text and inspect the evidence before reuse.
- Enter the regex in Pattern without slash delimiters. If the expression cannot compile, the summary changes to Regex needs review and shows the error message.
- Select Flags. The summary badge shows the normalized flag string such as
/dg, or no flags when none are selected. - Paste text in Sample text, choose Browse TXT, or drop a text, log, CSV, JSON, or Markdown file onto the textarea. If the file is over 4 MB, the file error explains that a smaller text file is required.
- Add an optional Replacement string when you need to preview rewritten text. Leave it blank when you only need match and capture evidence.
- Open Advanced if the run needs a different Match cap, Execution timeout, or Sample limit. The allowed ranges keep those values bounded.
- Read the summary count and warning badge, then open Match Preview, Run Metrics, Match Ledger, Capture Groups, and Replacement Text as needed.
- Use JSON when you need a structured record of the pattern, flags, summary, matches, captures, replacement text, and error state.
When the result shows an error, a timeout, truncation, or capped matches, fix that condition before treating the match count or replacement text as review evidence.
Interpreting Results:
The most important result is the combination of Status, Match count, Capture rows, and Warnings. A matched status means the current expression found at least one span in the tested sample. It does not mean the regex fully validates each line, covers every future input, or performs safely on larger hostile text.
| Output cue | Meaning | Follow-up |
|---|---|---|
| matched | At least one match was found in the tested sample. | Check Match Ledger to confirm the index, line, column, and exact span. |
| no match | The compiled expression found no match in the tested sample. | Confirm the flags, anchors, sample text, and truncation warning before broadening the pattern. |
| invalid | Pattern compilation, flag validation, worker startup, or timeout failed. | Use the summary error, then simplify the pattern or correct incompatible flags such as u plus v. |
| Replacement changed text | yes means the replacement output differs from the tested sample. | Inspect Replacement Text before copying a replacement string into another process. |
| Warnings | One or more guardrails affected the evidence or deserve review. | Treat truncation, capped matches, timeout, and zero-width notes as conditions to resolve or document. |
Use the same pattern, flags, match cap, timeout, and sample limit when comparing two regex revisions. Otherwise a changed match count may come from a changed guardrail instead of from the pattern edit.
Worked Examples:
Named Words In A Sentence
Pattern \b(?<word>[A-Z][a-z]+)\b with flags dg matches names such as Ada, Grace, and Katherine in the sample sentences. Match count shows 3, Capture rows shows one named capture per match, and Match Ledger gives the start and end positions for each name.
First Match Only Surprise
Using the same pattern with only the d flag compiles, but JavaScript returns the first match only. Match count shows 1, and Warnings says the expression is not global or sticky. Turning on g is the right fix when the goal is to list every matching word.
Replacement With A Named Capture
With pattern \b(?<word>[A-Z][a-z]+)\b, flags dg, and replacement [$<word>], the Replacement Text wraps each captured name in brackets. Replacement changed text becomes yes, which is the cue to compare the rewritten sample against the match ledger before exporting or copying it.
Large File Truncation
A 120,000-character log pasted with Sample limit set to 50,000 is tested only through the first 50,000 characters. Warnings reports the truncation, and Sample characters tested shows the tested count against the original count. Raise the limit or narrow the sample when matches near the end of the log matter.
FAQ:
Should the pattern include slash delimiters?
No. Enter the JavaScript pattern text only, such as \d{4}-\d{2}-\d{2}. The flag checkboxes provide the flags separately.
Why do I see only one match?
Without g or y, JavaScript returns only the first match. Turn on g when Match Ledger should list every non-overlapping match.
Why did my flags fail?
Unsupported flags cause an error, and u cannot be selected together with v. The summary error explains the flag problem before any match evidence is trusted.
What does a timeout mean?
The worker did not finish before the selected Execution timeout. Reduce the sample, simplify nested or overlapping pattern structure, or raise the timeout only for trusted text.
Are pasted samples sent to a server for matching?
Matching runs in the browser through a timeout-guarded worker. There is no server-side regex evaluation for the pattern or sample text.
Glossary:
- Regex
- A regular expression pattern used to find text that follows a rule.
- Flag
- A JavaScript RegExp option such as
g,i, ordthat changes matching behavior. - Capture group
- A parenthesized part of a regex that records a submatch for review or replacement.
- Named capture
- A capture group with a name, referenced in JavaScript replacement text with
$<name>. - Zero-width match
- A match that succeeds without consuming characters, such as a boundary or anchor.
- Match cap
- The maximum number of matches stored in the ledger for one run.
- Sample limit
- The maximum number of pasted or loaded characters tested in one run.
- ReDoS
- Regular expression denial of service, where a slow regex can consume excessive runtime on difficult input.
References:
- Regular expressions - JavaScript, MDN Web Docs, last modified October 30, 2025.
- RegExp() constructor, MDN Web Docs, last modified July 10, 2025.
- String.prototype.replace(), MDN Web Docs, last modified July 10, 2025.
- Regular expression Denial of Service - ReDoS, OWASP Foundation.