🔍 Developer Tools

Regex Tester

Test regular expressions with real-time matching, highlighted results, capture groups, and match positions.

How the Regex Tester works

Type a regex pattern in the Pattern field — no need for delimiters like /pattern/, just the pattern itself. Choose flags to control matching behavior (most commonly g for all matches and i for case-insensitive). Enter your test text, then click Test Match. The tool uses JavaScript's RegExp engine to find all matches, then displays them highlighted in context along with their positions and any capture groups.

Why the Regex Tester is Useful

Writing a regular expression correctly the first time is rare, even for experienced developers. The syntax is compressed to the point of being cryptic, flags change behaviour in non-obvious ways, and a single misplaced character can turn a working pattern into one that silently matches nothing — or matches everything. Having an immediate visual feedback loop fixes all of that: type a pattern, see every match highlighted in the actual test text, inspect each match's position and capture groups, and iterate in real time until the pattern behaves exactly as intended. This is the fastest way to build and debug regex patterns, whether you're validating email addresses, parsing log output, or extracting structured data from messy text.

Key Features

  • Pattern field without delimiters: Enter just the pattern — no surrounding slashes or quotes needed. The tool wraps the pattern in JavaScript's RegExp constructor automatically, so what you type is exactly what gets tested.
  • Six flag checkboxes: Global (g), case-insensitive (i), multiline (m), dotall (s), unicode (u), and sticky (y) — all toggleable with a click. The global flag is on by default since finding all matches is the most common use case.
  • Matches highlighted in context: A dark-background text area shows your test string with every match highlighted in gold — so you can see exactly which parts of the text the pattern is catching and which it's skipping.
  • Match list with positions and capture groups: Every match is listed below the highlighted view with its index (position in the string), full matched text, and the content of any numbered capture groups.
  • 300ms debounce for live matching: Results update automatically 300ms after you stop typing — fast enough to feel live, slow enough not to hammer the engine on every keystroke.
  • Quick reference sidebar: A permanently visible sidebar lists all common regex tokens (\d, \w, \s, ., *, +, ?, ^, $, [], (), {n,m}) and six common patterns (email, URL, digits, words, HTML tag, hex colour).
  • Sample loader: One click loads a working email-matching pattern with test text and capture groups, giving you a concrete working example to learn from immediately.

Real-Life Use Cases

  • Input validation patterns: Build and test email, phone number, postcode, or credit card validation patterns before embedding them in form validation code — testing edge cases visually before shipping.
  • Log file parsing: Paste a sample of server log output and develop a pattern that extracts IP addresses, error codes, timestamps, or request paths from each line before applying it at scale.
  • Find-and-replace preparation: Test a regex before using it in a code editor's find-and-replace — seeing exactly what will be matched before committing to the replacement prevents unexpected changes to unintended parts of the file.
  • Data extraction from messy text: Pull structured information (prices, dates, product codes, phone numbers) from unstructured text copied from PDFs, emails, or web pages.
  • Learning regex interactively: The best way to understand regex syntax is to experiment with it. Use the quick reference sidebar to pick tokens, drop them into the pattern field, and immediately see what they match in the test string.

Who Can Use This Tool

Backend and frontend developers writing validation logic or parsing code, DevOps engineers building log analysis patterns, QA engineers creating test data extraction rules, data analysts using regex in SQL, Python, or Excel, students working through a programming course that covers pattern matching, and any developer who has ever stared at a regex that "should work" and needed to see exactly what it's matching before finding the bug.

Tips & Best Practices

  • Always start with the global (g) flag: Without it, the tester stops after the first match. Enable g from the start so you can see the full picture of what your pattern catches across the entire test string.
  • Use the Load Sample to understand capture groups: The sample loads an email pattern with three capture groups — username, domain, and TLD. See how each group appears separately in the match list, which is the fastest way to understand how capturing works in practice.
  • Use non-capturing groups for structure without extraction: If you need parentheses for grouping but don't need to capture the content, use (?:...) instead of (...). This is slightly faster and keeps the match list clean.
  • Test edge cases explicitly: Include intentionally invalid examples in your test string — an email without @, a phone number with too many digits — to verify that your pattern correctly rejects inputs that should fail, not just accepts ones that should pass.
  • Use \b for whole-word matching: If your pattern should only match whole words (not substrings inside longer words), wrap it with word boundary assertions: \bword\b. This prevents "cat" from matching inside "concatenate".

Frequently Asked Questions

What is a regular expression (regex)?
A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Regex is used for string matching, validation (like emails or phone numbers), find-and-replace operations, and data extraction in programming, text editors, and command-line tools.
What do regex flags mean?
Regex flags modify how the pattern matching behaves:g (global) — finds all matches instead of stopping at the first.i (case-insensitive) — ignores letter case.m (multiline) — makes ^ and $ match the start/end of each line.s (dotall) — makes the dot (.) match newline characters.u (unicode) — enables proper Unicode matching.y (sticky) — matches only from the exact lastIndex position.
How do I test a regex pattern online?
Enter your regex pattern in the Pattern field (without delimiters like /pattern/), select any flags you need, then type or paste your test text. Matches are shown in real-time with highlighting, match count, positions, and capture group details.
What are capture groups in regex?
Capture groups are parts of a regex pattern enclosed in parentheses ( ). They let you extract specific portions of a match. For example, in the pattern (\d{3})-(\d{4}), the first group captures a 3-digit area code and the second captures a 4-digit number. Each group is numbered starting from 1, with group 0 being the full match.
What are the most common regex patterns?
Common regex building blocks include:\d — any digit (0-9)\w — any word character (a-z, A-Z, 0-9, _)\s — any whitespace character. — any character except newline* — zero or more of the preceding element+ — one or more? — zero or one (makes preceding element optional)^ — start of string or line$ — end of string or line[abc] — character set (matches a, b, or c)(ab|cd) — alternation (matches ab or cd)
Browse all tools JSON Formatter