Match, explain, replace, reuse

Test a regular expression against the file you are reading

Open Regex Playground from the current document, enter a pattern, and see every match highlighted in the viewer. Inspect numbered and named groups, preview replacements, keep test cases, and copy a working snippet for JavaScript, C#, or PowerShell.

  • Current document or custom text
  • Named groups
  • Replace preview
  • Snippet export
Regex Playground matching JavaScript assignments with named capture-group details
The active match stays connected to its highlighted location in the document and exposes its capture groups.
Workflow

Move from a pattern to evidence

A match count is useful, but a reliable pattern needs context, capture-group inspection, negative cases, and a replacement or code path you can verify.

1

Choose the test input

Use the open document so matches highlight in context, or switch to custom text that remains only in the active session.

2

Inspect every match

Enable flags, move through the result list, and review complete matches, numbered groups, and named groups.

3

Make it reusable

Preview a replacement, add pass/fail test cases, save the pattern, and copy a language-specific snippet.

Example

Find assignment targets in minified JavaScript

A named group makes the result self-describing and gives the replacement preview a stable reference.

Pattern

Capture a valid identifier before equals

The global flag finds every assignment-like occurrence in the current document.

(?<name>[A-Za-z_$][\w$]*)\s*=
Selected match

Inspect the complete value and named group

Clicking a result connects the list, details panel, and source highlight.

Complete match: services =
Group 1: services
Named group:
  name: services

Flags: g
Source: current document
Hands-on tutorial

Turn environment assignments into named, tested matches

This lesson starts with a small environment-style document, captures the key and value separately, previews a replacement, and records tests that protect the pattern from future edits.

  1. Choose Custom text and paste a controlled sample

    Open Regex Playground with Ctrl+Alt+R or from General tools, then choose Custom text. Custom text remains in the active session and is useful while you learn because unrelated document content cannot create surprise matches.

    API_URL=https://api.example.com
    TIMEOUT_MS=5000
    DEBUG=true
    not an assignment
  2. Start with line boundaries and one complete match

    Enter ^[A-Z][A-Z0-9_]*=.*$ without surrounding slash characters. Enable multiline m so ^ and $ apply to each line, then enable global g so the result list contains all three assignments instead of only the first.

  3. Replace anonymous pieces with named groups

    Change the pattern to ^(?<key>[A-Z][A-Z0-9_]*)=(?<value>.*)$. Select a match and verify that the details show the complete line plus named groups key and value. Named groups make later replacement text and generated snippets easier to understand.

  4. Inspect every match in its original context

    Move through the three result rows. Confirm that not an assignment is excluded and that the value group may contain punctuation such as :, /, and periods. When using Current document, selecting a result also jumps to its highlighted source location.

  5. Preview a named-group replacement

    Open Advanced and enter "$<key>": "$<value>" as the replacement. The preview should turn each assignment into a JSON-like property line. Replacement is a preview only; it does not mutate the document or custom text.

  6. Add tests for both success and rejection

    Add a match assertion for PORT=8080, a no-match assertion for lowercase=value, and a count-equals assertion of three for the complete sample. If you depend on the exact replacement, add a replacement-equals test as well.

  7. Copy the complete expression or a language snippet

    Review the displayed /pattern/gm form, save the pattern with a meaningful name, and copy JavaScript, C#, or PowerShell output. Generated code is a handoff: run it against the same positive and negative cases in the destination runtime before shipping it.

Practice: make the pattern stricter without breaking it

Try each change separately and watch the live results and tests. Restore the pattern when a negative case begins to match.

  • Allow spaces around the equals sign without capturing them.
  • Reject an empty key while still allowing an empty value.
  • Add a line beginning with # and prove it does not match.
  • Add a value containing another equals sign and inspect the captured value.
  • Disable multiline and explain why only whole-input anchors remain.
  • Remove global and explain why the result list stops after the first match.
Match and replace

Preview the transformation before copying it

Advanced mode keeps replacement output, test cases, and snippet export in the same workspace as the live matches.

Regex match results and named capture groups for JavaScript source
Start with real matches and inspect the active capture groups.
Regex Playground showing named-group replacement preview, test cases, and snippet export
Advanced mode shows the replacement preview and ready-to-adapt JavaScript, C#, and PowerShell snippets.

Prove the expected cases

Add short examples for the ordinary values the pattern must accept. Keep each case focused so a future failure tells you which boundary changed instead of merely reporting that one large sample no longer matches.

Protect the boundaries

Test empty values, punctuation, whitespace, line breaks, Unicode, and the start or end of the input when they matter. These are where a broad character class or a misplaced anchor usually becomes visible.

Record negative cases

Include believable text that must not match, not only obviously unrelated strings. A passing positive case proves the pattern can find something; a passing negative case helps prove that it finds the right thing.

Pattern design lesson

Choose flags because the input demands them

Flags change the meaning or traversal of the expression. Enable each one for a reason you can explain rather than copying a familiar bundle of letters.

FlagUse it whenCommon surprise
g globalYou need every match, a full replacement preview, or an accurate count.Without it, a correct pattern may appear to find only the first occurrence.
i ignore caseLetter case is not meaningful in the source.It can accept values that a case-sensitive identifier or protocol should reject.
m multiline^ and $ should refer to each line.It does not make the dot character cross line breaks.
s dot allA dot should include newline characters inside a multi-line value.A broad .* can consume much more text than intended.
u UnicodeThe pattern uses Unicode-aware escapes or must treat code points correctly.Some older runtimes or copied snippets may support a different feature set.
y stickyMatching must begin exactly at the current engine position.It is useful for tokenizers but surprising for ordinary document search.

The expression is valid but finds nothing

Check input source, case, anchors, and flags. Test a smaller literal fragment, then rebuild the boundary rules around a known match.

A match consumes too much text

Inspect greedy quantifiers such as .*. Use a narrower character class, a reluctant quantifier, or a clear delimiter when the input has one.

The replacement looks right but the document is unchanged

That is intentional. Replacement is a preview. Copy the result only after its test cases and visible output are correct.

A complex pattern times out

Simplify nested repetition and ambiguous alternatives. Patterns run in a worker, stop after roughly 1.5 seconds, and cap results at 500 so a catastrophic expression cannot freeze the viewer.

Learning outcome: you should be able to explain the input, boundaries, groups, flags, positive cases, negative cases, and replacement behavior of a pattern before copying it into code.

Tools

Keep the pattern understandable after today

Flags

  • Global g
  • Ignore case i
  • Multiline m
  • Dot all, Unicode, and sticky

Match details

  • Complete match value
  • Numbered groups
  • Named groups
  • Jump to the highlighted source

Replacement

  • Live preview
  • Numbered references such as $1
  • Named references such as $<name>
  • No mutation of the source document

Test cases

  • Examples expected to match
  • Examples expected not to match
  • Visible pass/fail summary
  • Regression checks beside the pattern

Saved patterns

  • Optional names
  • Remembered pattern and flags
  • Reusable history
  • Local storage only

Snippet export

  • JavaScript RegExp
  • C# Regex
  • PowerShell -match and replacement
  • Copy the complete expression
Custom test text remains session-local.

It is not written to pattern history, settings, or extension storage. Saved patterns and test definitions are stored locally and may be sensitive if you include private examples in them.

FAQ

Regex Playground questions

Does the replacement modify my document?

No. Replacement is a preview. Copy the result when you are satisfied with it.

Can I test text unrelated to the current file?

Yes. Switch the input to Custom text. That text stays only in the active viewer session.

Why use test cases if the live document matches?

A live match proves the pattern works for today’s sample. Positive and negative test cases help show that it still behaves correctly after the pattern changes.

Are all JavaScript regex features supported?

The pattern is evaluated by the installed runtime. Feature support therefore follows the browser or WebView2 JavaScript engine in use.

Related guides

Test the pattern where the text already is

Open Regex Playground from the document, inspect the matches in context, and leave with a replacement or snippet you have actually checked.