JSON StudioGuidesMore toolsFeature requests中文

JavaScript regex tester: flags, capture groups and replacement

Use the regex tester to inspect how a JavaScript pattern matches real text before adding it to code. Pattern syntax depends on the regex engine; a working JavaScript expression is not automatically compatible with Java, Python or Go.

Open this tool →

How to use the tool

  1. Enter a pattern and flags, then paste the text to test.
  2. Use match preview to inspect highlighted ranges and captured groups.
  3. Switch to replacement to preview substitutions, or extraction to select captures and export results.
  4. Test positive and negative examples, including empty text and multiline input, before using the pattern in application code.

An example to test

Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Flags: g
Text: 2026-10-07 / 2024-02-29
Replacement: $<day>/$<month>/$<year>

Flags and captures

g finds multiple matches, i ignores case and m changes the behavior of line anchors. s lets a dot match line terminators. Named captures make extraction and replacement easier to read. A replacement may use $1 for a numbered group or $<name> for a named group.

Match does not mean complete validation

A date-shaped pattern only checks text structure; it does not prove a date exists. Decide whether partial matches are acceptable or whether you need full-input anchors. Long inputs or patterns with excessive backtracking can hit the tool’s time or result limits; reduce the sample or simplify the expression.

Frequently asked questions

Why does a pattern match only one occurrence?

Check whether the g flag is enabled when you want multiple occurrences.

Why does a date regex accept an invalid calendar date?

Digit patterns validate shape, not calendar rules. Parse the matched date with date logic if calendar validity matters.

Related guides