Regex Tester
Pick an example below, or click tokens on the left to build your pattern step by step.
Explanation
Enter a valid pattern to see a step-by-step breakdown.
Upload TXT, CSV, or JSON as test text. Export match results as TXT or JSON.
How to Use
Enter a regex pattern and test string — matches update in real time with highlighting and capture group details.
Uses native JavaScript RegExp (ECMAScript). All processing runs in your browser; nothing is uploaded.
What Is Regex
A regular expression (regex) is a sequence of characters that defines a search pattern. Developers use regex to validate input, extract data, and replace text in strings.
This Regex Tester runs JavaScript RegExp in your browser so you can see matches, positions, and capture groups instantly.
How Regex Works
The engine scans your test text and tries to match the pattern left to right. Metacharacters like ., *, +, ?, [], (), {}, ^, $, and | control how characters are matched.
Flags change behavior: g finds all matches, i ignores case, m treats ^ and $ as line anchors, s lets . match newlines, u enables Unicode, and y sticks to lastIndex.
Regex Use Cases
Common uses include email and URL validation, parsing logs, extracting numbers, cleaning CSV data, and refactoring code with search-and-replace.
Use the pattern library on this page to load proven templates for emails, phone numbers, UUIDs, HTML tags, and more.
Regex Best Practices
Prefer simple patterns, test edge cases, and anchor when validating whole strings (^ … $). Use non-capturing groups (?:) when you do not need extracted values.
For passwords and security-sensitive rules, combine regex with additional server-side checks rather than relying on regex alone.
Common Regex Mistakes
Forgetting to escape special characters, greedy quantifiers matching too much, and assuming regex is the same across languages are frequent pitfalls.
In JavaScript, remember that replace and match behavior depend on flags — especially global (g) — and invalid patterns throw SyntaxError with a position hint.
FAQ
- What is regex?
- Regex (regular expressions) are patterns for matching and manipulating text. They are built from literals and special operators.
- How do I test regex online?
- Enter your pattern and test string on this page. Matches highlight in real time with index, length, and capture groups.
- What does \d mean?
- \d matches any digit character (0–9) in JavaScript regex.
- What does \w mean?
- \w matches word characters: letters, digits, and underscore [A-Za-z0-9_].
- What does + mean?
- The + quantifier means one or more of the preceding token.
- What does * mean?
- The * quantifier means zero or more of the preceding token.
- What is a capture group?
- Parentheses ( ) create a capture group. The matched substring is stored as $1, $2, … in replacements and in match.groups.
- How do I validate email with regex?
- Use a pattern like ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ with anchors for full-string validation. Load the Email example from the library.
- How do I match URLs?
- Match http:// or https:// followed by domain and path characters. See the URL Validation template in the pattern library.
- What is regex multiline mode?
- The m flag makes ^ and $ match the start and end of each line instead of the whole string.
- What is regex global mode?
- The g flag finds all matches in the text instead of stopping at the first match.
- How do I extract numbers with regex?
- Use \d+ to match sequences of digits. With the g flag, all number groups in the text are returned.
- How do I match phone numbers?
- Digit patterns such as \b\d{10,15}\b work for many formats. Adjust for country-specific rules.
- How do I test regex in JavaScript?
- Use new RegExp(pattern, flags) or /pattern/flags. This tool uses the same engine as your browser.
- How do I debug regex?
- Check invalid-pattern errors, toggle flags, inspect capture groups, and use the explanation panel to see what each token means.
- What are regex flags?
- Flags are letters after the closing / that set g, i, m, s, u, or y behavior in JavaScript.
- Can regex validate passwords?
- Regex can enforce character rules (length, letters, digits). Always add server-side checks for real security.
- What is regex lookahead?
- (?=…) is a positive lookahead: it asserts a pattern ahead without consuming characters.
- What is regex lookbehind?
- (?<=…) and (?<!…) are lookbehinds in modern JavaScript for assertions before the current position.
- What is regex tester used for?
- To prototype, validate, and debug regular expressions before using them in apps, scripts, or data pipelines.