ToolMight LogoToolMight

RegEx Tester

Test and debug JavaScript regular expressions directly in your browser. Enter a pattern, select RegExp flags, and inspect highlighted matches against your test string. Evaluation runs locally in client-side memory without sending input data to ToolMight's servers.

Loading Tool...

Learn About This Tool

JavaScript regular expression basics

This tool tests JavaScript regular expressions using the browser's native ECMAScript RegExp engine.

In JavaScript, regular expressions can be written as a literal or constructed using the RegExp object. Use a regex literal when the pattern is static in source code, and use RegExp when the pattern or flags are constructed dynamically at runtime.

// Regex literal (static pattern)
const regex = /\b[A-Za-z]+\b/g;

// RegExp constructor (dynamic pattern)
const regex = new RegExp("\\b[A-Za-z]+\\b", "g");
  • Character Classes: \d (digits), \w (word characters), \s (whitespace), . (wildcard except newlines)
  • Quantifiers: * (zero or more), + (one or more), ? (optional / zero or one), {n,m} (between n and m)
  • Anchors: ^ (start of input / line with m flag) and $ (end of input / line with m flag)

RegExp flags reference

Flags alter how the matching engine evaluates input text:

FlagNameDescription
gGlobalFinds multiple matches instead of stopping after the first match.
iIgnore caseMatches letters without case sensitivity (A-Z matches a-z).
mMultilineMakes ^ and $ anchors operate on individual lines separated by newlines.
sDotAllAllows the dot (.) wildcard to match line terminators (\n).
uUnicodeEnables Unicode-aware matching and code-point escapes (\u{...}).
yStickyRequires each match to begin at the regex's current lastIndex.

Capture groups and assertions

Parentheses create capture groups to isolate subpatterns. Modern JavaScript supports numbered groups (\d{4})-(\d{2}) and named capture groups (?<year>\d{4})-(?<month>\d{2}).

Lookaround assertions check text positions surrounding a match without consuming characters:

AssertionMeaningExample
(?=...)Positive lookaheadUSD(?=\d+) matches USD in USD100
(?!...)Negative lookaheaduser(?!admin) matches user in user123
(?<=...)Positive lookbehind(?<=\$)\d+ matches 100 in $100
(?<!...)Negative lookbehind(?<!bar)foo matches foo in bazfoo

Catastrophic backtracking and ReDoS

Performance Warning: Pathological PatternsNested or overlapping quantifiers like ^(a+)+$ force the engine to explore thousands of execution paths when input does not match, potentially freezing the evaluation thread.

In this browser tool, a pathological pattern evaluated against non-matching text (such as aaaaaaaaaaaaaaaaaaaaab) can make the browser tab temporarily unresponsive. In backend applications, such patterns represent Regular Expression Denial of Service (ReDoS) security vulnerabilities when handling untrusted user input.

How to Use RegEx Tester

1

Enter your regex

Type the pattern into the RegEx input box without surrounding / delimiters.

2

Choose flags

Configure flags such as g (global), i (ignore case), or m (multiline) in the flags field.

3

Enter test text

Paste the string, log file, or code snippet you want to test against.

4

Inspect matches

View highlighted match ranges and the total match count displayed in the side panel.

5

Fix syntax errors

If the pattern or flags contain syntax errors, an error badge appears immediately.

Code Implementations

Copy & paste production-ready code snippets for RegEx Tester in your language of choice

File: regex_test.py
Python
import re

pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
text = "Contact [email protected] or [email protected] for info."

# Find all email matches
matches = re.findall(pattern, text)
print("Found emails:", matches)

# Replace emails with masked placeholder
masked_text = re.sub(pattern, "[REDACTED_EMAIL]", text)
print("Masked text:", masked_text)

Frequently Asked Questions

The tool uses your browser's native ECMAScript JavaScript RegExp engine. It tests standard JavaScript regex syntax and flags.
Flags modify matching rules: g finds multiple matches, i ignores case, m enables multiline anchors, s allows dot matching across newlines, u enables Unicode code points, and y enforces sticky matching.
Regex literals (/pattern/g) are evaluated when the script is loaded. The new RegExp() constructor compiles patterns at runtime, which is useful when constructing patterns dynamically from variables.
Greedy quantifiers (e.g. .*) match as much text as possible while allowing the pattern to succeed. Lazy quantifiers (e.g. .*?) match as little text as possible.
Catastrophic backtracking occurs when ambiguous nested quantifiers force the engine to explore exponential match combinations on failing inputs, hanging the thread.
Prepend a backslash before special characters when matching literal symbols: \. for a period, \[ for an opening bracket, or \$ for a dollar sign.
No. Regex evaluation runs entirely in your browser using JavaScript. Neither your pattern nor your test string is sent to a server.

Related tools

Deep Dives & Guides

Master this tool with our expert tutorials and best practices.