JavaScript Regex Tester & Debugger

Regexx

Write it. Test it. Understand it.

Test JavaScript regular expressions with live match highlighting, capture group details, flags, and a replace preview. Your patterns and test text are processed in your browser.

Test a regular expression

Enter a pattern, choose the flags, and add a sample string. Matches appear below as you type. Use the quick patterns for common starting points or consult the reference guide when you need a reminder.

Browser-based processing
Enter a pattern above to get started.
Test string
Replace

Replacement preview


    

Quick patterns

Matches

Syntax at a glance

JavaScript Regex Quick Reference

Common tokens, quantifiers, groups, anchors, and flags.

A practical guide for developers

What is Regexx?

Regexx is a free online JavaScript regex tester for writing, checking, and refining regular expressions. Enter a pattern and a test string to see matching text highlighted, inspect match positions and capture groups, and preview a replacement without changing the original input.

Regular expressions describe text patterns. They are useful when a task is easier to express as a rule than as a sequence of manual string operations: finding identifiers in logs, checking the shape of form input, extracting values, locating repeated whitespace, or transforming text in an editor. Regexx gives you a focused place to test those rules against real examples before using them in an application.

What can you use a regex tester for?

Input checks

Check whether a value follows an expected shape, such as a product code, username, date string, or slug. Test valid examples and near-misses so the pattern does not accept more than you intended.

Text extraction

Find repeated identifiers, timestamps, tags, key-value pairs, or structured fragments in logs and documents. Capture groups let you isolate the parts you need from each match.

Search and cleanup

Locate multiple spaces, inconsistent separators, unwanted prefixes, or repeated text. A replacement expression can normalize those fragments while preserving selected parts through backreferences.

Developer workflows

Prototype patterns for JavaScript code, editors, data preparation, test fixtures, and log inspection. Confirm how a pattern behaves on multiline input and edge cases before adding it to a project.

Common JavaScript regex examples

These examples are starting points, not universal validation rules. Load one into the tester, add realistic sample data, and adjust it to match the exact format your application expects.

Whole-number integer

Validation shape
^-?\d+$

Matches an optional minus sign followed by one or more digits, with no extra characters before or after.

ISO date shape

Text format
^\d{4}-\d{2}-\d{2}$

Checks the YYYY-MM-DD shape. It does not prove that the day exists in the specified month; validate calendar values separately.

Repeated whitespace

Cleanup
\s+

Finds one or more whitespace characters, useful when normalizing repeated spaces, tabs, or line breaks.

Key-value line

Extraction
^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$

Captures a simple identifier and its non-empty value. Enable m to apply the anchors to each line of a multiline string.

Lowercase URL slug

Format
^[a-z0-9]+(?:-[a-z0-9]+)*$

Matches lowercase letters and digits separated by single hyphens, without leading or trailing separators.

Simple email shape

Starting point
^[^\s@]+@[^\s@]+\.[^\s@]+$

Checks a common email-like structure. It is not a complete implementation of every valid email address format.

How to build a reliable regular expression

A good pattern starts with examples, not with the most compact expression possible. Build it in small steps and test both the values you expect to match and values that should be rejected.

  1. Define the exact input. Decide whether the pattern should match the entire string or only find a fragment inside it. Use ^ and $ when the whole value must match.
  2. Start with the simplest rule. Identify the characters, boundaries, and repetition involved. Add groups only when you need to capture or combine parts.
  3. Add realistic test cases. Include normal examples, empty values, extra spaces, punctuation, line breaks, and malformed input where relevant.
  4. Choose flags deliberately. Use i for case-insensitive matching, m for line-based anchors, s when a dot should include line breaks, and g to find every occurrence.
  5. Review the replacement separately. If you use groups, confirm that $1, $2, or named backreferences produce the intended output.

Understand flags, anchors, and capture groups

Anchors define position

^ and $ match positions at the beginning and end of the input. With the m flag, they also match at line boundaries. Anchors do not consume characters; they constrain where a match can begin or end.

Quantifiers define repetition

*, +, and ? describe how many times a token may appear. By default, quantifiers are greedy. Adding ? after a quantifier makes it lazy, so it takes the shortest match that satisfies the rest of the pattern.

Groups capture useful values

(...) creates a numbered capture group. (?:...) groups part of a pattern without capturing it. Named groups such as (?<code>...) make extracted values easier to identify.

Lookarounds check context

Lookahead and lookbehind assertions check what appears before or after a position without including that context in the matched text. They are useful when a value must be adjacent to a delimiter or another token.

JavaScript RegExp compatibility

Regexx uses the JavaScript RegExp engine supplied by the browser. This makes it useful for testing patterns intended for frontend JavaScript and other environments that follow JavaScript regular-expression syntax. Modern browsers support named capture groups, lookahead, lookbehind, Unicode-aware matching, and additional regular-expression features, but exact support can depend on the browser version.

Regular-expression flavors are not interchangeable. A pattern copied from a PCRE, Python, .NET, Java, or Ruby example may use syntax that JavaScript does not recognize or interpret differently. For example, PCRE-specific constructs such as \K and conditional patterns are not part of JavaScript RegExp. Always test a pattern in the same flavor that will run in production.

Know when regex is the right tool

Regular expressions work best for recognizable text patterns and local transformations. They are not a substitute for a parser. Use a JSON parser to read nested JSON, an HTML parser to inspect document structure, and a programming-language parser when syntax and nesting matter. A regex can help find a simple fragment inside those formats, but it cannot reliably interpret every nested or escaped structure.

Also be careful with patterns that combine nested or overlapping repetition. Some backtracking expressions can explore a very large number of alternatives when the input almost matches but ultimately fails. This can make a match unexpectedly slow. Keep patterns specific, avoid unnecessary nested quantifiers, and test long or adversarial examples when input may come from untrusted users.

Browser-based processing

Regexx performs pattern matching and replacement in your browser. Matching runs in a dedicated Web Worker so the main interface can remain responsive while the test string is processed. The pattern and sample text are not sent to a Regexx processing backend, and the original test string remains unchanged when you preview a replacement.

A Web Worker improves interface responsiveness; it does not make every pattern fast or remove the CPU and memory limits of the device. A poorly constructed expression can still consume significant local processing time. Use the tester to examine behavior carefully before relying on a complex pattern in a production workflow.

Answers to common questions

Frequently asked questions about Regexx

The answers below are shown directly on the page, so you can scan the details without opening or expanding hidden panels.

Is Regexx free to use?

Yes. Regexx is a free online JavaScript regex tester. You can test patterns, inspect matches, use capture groups, and preview replacements without creating an account.

Which regular expression flavor does Regexx support?

Regexx uses the JavaScript RegExp engine available in your browser. It supports JavaScript regular expression syntax, including named capture groups, lookahead, lookbehind in modern browsers, and the g, i, m, and s flags exposed by the interface. PCRE-only syntax such as \K and conditional patterns is not supported.

Does my test text get uploaded?

Regex matching and replacement are performed in your browser. The pattern and test string are passed to a local Web Worker for processing and are not uploaded to a Regexx processing server.

What do the g, i, m, and s flags do?

The g flag finds all matches, i ignores letter case, m changes the behavior of the ^ and $ anchors so they work at line boundaries, and s makes the dot character match line terminators as well.

How do I use capture groups in a replacement?

Use parentheses in the pattern to create capturing groups. In the replacement field, refer to numbered groups with $1, $2, and so on, or named groups with $<name>. Regexx displays a preview and leaves the original test string unchanged.

Can a regular expression fully validate an email address?

A practical regex can check the common shape of an email address, but complete email validation involves rules and edge cases that are better handled with a dedicated validation process and, ultimately, confirmation that the address can receive mail.

Can I use regex to parse HTML or JSON?

Regex is useful for locating simple text patterns inside markup or JSON strings, but it is not a reliable parser for nested structures. Use an HTML or JSON parser when you need to understand document structure, nesting, or escaped values.

Why does a valid pattern return no matches?

Check whether the pattern is anchored, whether case or multiline behavior requires a flag, whether whitespace or line endings differ from the example, and whether the pattern expects a different format. A valid pattern can correctly return zero matches when the test string does not satisfy it.

Why can some regular expressions run slowly?

Some patterns create many alternative paths for a backtracking regex engine, especially when nested or overlapping quantifiers are used. This can cause excessive processing time on certain inputs. A Web Worker keeps matching away from the main interface thread, but it does not make an inefficient pattern computationally cheap.

Can I share a regex with someone?

Regexx does not currently create shareable pattern links. Copy the pattern and its flags into a message, code review, or documentation so the recipient can reproduce the test.