Regex Tester

Test JavaScript regular expressions in your browser. Toggle g, i, m, s, u, and y. Inspect capture groups. Preview String.replace with $1, $&, $`, and $'.

Reviewed by Olgun Ozoktas

JavaScript regex
//

JavaScript String.replace patterns: $1, $&, $`, $', and $$.

0 found
Enter a pattern to start matching

How to Test Regular Expressions Online

  1. 1

    Enter your regex pattern

    Type or paste your regular expression into the pattern field. The tool accepts any valid JavaScript regex syntax including character classes, quantifiers, groups, and lookaround assertions.
  2. 2

    Set JavaScript regex flags

    Toggle g (all matches), i (ignore case), m (^ and $ at line ends), s (dot matches newline), u (Unicode), and y (sticky at lastIndex).
  3. 3

    Add a test string

    Paste text to test. You can add more than one string. Matches highlight as you type.
  4. 4

    Preview replace with $1

    Enter a replacement such as $1. The preview uses JavaScript String.replace. Load sample uses pattern (\w+), replace $1, and the string hello world.

Common Use Cases

1

Email Validation

Validate email addresses with patterns like [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. Test edge cases such as subdomains, plus addressing, and international TLDs before deploying your validation logic.
2

Data Extraction

Extract structured data from unstructured text -- pull phone numbers, dates, URLs, IP addresses, or currency amounts from documents, logs, or API responses using targeted capture groups.
3

Search and Replace

Build and test find-and-replace patterns before running them on production data. Use capture groups with backreferences to reformat dates, swap name order, or restructure CSV columns.
4

Log Parsing

Write patterns that parse server logs, application output, or error messages. Extract timestamps, severity levels, request paths, and error codes from common log formats like Apache, Nginx, and syslog.

Why use our Regex Tester?

This tool uses the JavaScript regex engine. Matches highlight as you type. Capture groups show as $1, $2, and so on. The Replace field runs String.replace with $1, $&, $`, and $'. Flags: g, i, m, s, u, and y.

This page tests JavaScript regular expressions in your browser. Matches highlight as you type. Capture groups show as $1, $2, and so on. The Replace field runs JavaScript String.replace, so $1, $&, $`, and $' work the same as in your code.

Supported flags are g, i, m, s, u, and y. The u flag enables Unicode property escapes. The y flag is sticky and matches only at lastIndex. Other languages share much of this syntax, but this tool does not emulate Python, PCRE, or Go engines.

Use the sample path to confirm replace: pattern (\w+), replace $1, test string hello world. Pair this tool with the Glob Pattern Tester for file paths, or the Diff Checker to compare text after a replace. Processing stays in this browser. The page does not upload your test strings.

How It Compares

This tester uses the JavaScript regex engine in your browser. Your pattern and test strings stay in this tab. The page does not upload them. Other sites may offer extra engines or a pattern library. This page focuses on JavaScript match, flags, and String.replace with $1.

Regex Tips & Best Practices

1
Use character classes like \d, \w, and \s instead of broad patterns like.* to make your regex faster and more precise. Specific classes reduce backtracking and clearly communicate intent to other developers.
2
Anchor your patterns with ^ and $ when you need to match an entire string. Without anchors, your regex will match substrings, which can lead to false positives in validation scenarios.
3
Avoid nested quantifiers such as (a+)+ or (.*?)* that can cause catastrophic backtracking. If your regex takes noticeably long on certain inputs, nested repetition is usually the culprit.
4
Use non-capturing groups (?:..) when you need grouping for alternation or quantifiers but do not need to extract the matched text. This improves performance and keeps your capture group numbering clean.
5
Test your regex against edge cases, not just the happy path. Empty strings, very long inputs, special characters, and unicode text can all reveal problems that normal test data hides.

Frequently Asked Questions

1

What regex syntax is supported?

This tool uses the JavaScript regex engine. It supports lookahead, lookbehind, Unicode with the u flag, and JavaScript replacement patterns such as $1.
2

What do the flags mean?

g finds all matches. i ignores case. m makes ^ and $ match line ends. s lets . match newlines. u enables Unicode. y is sticky and matches only at lastIndex.
3

How do I match special characters?

Escape special characters with a backslash. For example, \. matches a literal dot, \$ matches a dollar sign.
4

What are capture groups?

Parentheses () create capture groups. The Replace field uses JavaScript String.replace, so $1 inserts group 1. $& is the full match. $` is the text before. $' is the text after.
5

Is my data secure?

Yes! All regex processing happens entirely in your browser. Your test data is never sent to any server.
6

Can I test regex for Python or PHP, not just JavaScript?

This tool runs JavaScript's regex engine, which covers the vast majority of common patterns. Most basic to intermediate regex syntax (character classes, quantifiers, groups, lookahead) works identically across JavaScript, Python, PHP (PCRE), and Java. For engine-specific features like atomic groups or possessive quantifiers, test in the target language.
7

What is catastrophic backtracking and how do I avoid it?

Catastrophic backtracking happens when a regex engine tries an exponential number of paths to match a pattern, causing extreme slowdown. Common culprit: nested quantifiers like (a+)+. Avoid it by using specific character classes instead of.*, anchoring patterns with ^ and $, and preferring possessive quantifiers or atomic groups when your engine supports them.
8

How do I use named capture groups?

Use the syntax (?pattern) to create a named group. For example, (?\d{4})-(?\d{2}) captures year and month by name. In JavaScript, access them via match.groups.year. Named groups make complex patterns more readable and maintainable.
9

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers like * and + match as much text as possible, while lazy versions *? and +? match as little as possible. For example, against 'bold', the pattern <.*> greedily matches the entire string, but <.*?> lazily matches just ''. Use lazy quantifiers when you need the shortest possible match.
10

Can I use this regex tester offline?

Once the page loads, all regex processing runs entirely in your browser with no server calls. You can test patterns even if your internet connection drops. Bookmark the page for quick offline access anytime.

Rate This Tool

0/1000

Get Weekly Tools

Suggest a Tool