JavaScript Regex Tester
A client-side utility to test JavaScript Regular Expressions against text data, featuring real-time highlighting and capture group extraction.
Highlights
Extraction (Capture Groups)
Debugging JavaScript Regular Expressions
This tool uses the native JavaScript RegExp engine running in your browser, ensuring 100% compatibility with your actual web code. It supports modern features including Lookaheads, Lookbehinds, and Named Capture Groups.
Regex Cheat Sheet (Quick Reference)
Here are the most commonly searched tokens and patterns:
Character Classes
.: Matches any character (except newline, unlesssflag is on).\d/\D: Digit / Non-digit.\w/\W: Alphanumeric Word / Non-word.\s/\S: Whitespace / Non-whitespace.[a-z]: Character Set (matches any one character inside).[^a-z]: Negated Set (matches anything except what is inside).
Quantifiers
*: 0 or more times.+: 1 or more times.?: 0 or 1 time (Optional).{3}: Exactly 3 times.{3,7}: Between 3 and 7 times.
Anchors & Groups
^/$: Start / End of string.\b: Word Boundary (start or end of a word).(...): Capture Group (extracts data).(?:...): Non-Capturing Group (groups logic without extracting).(?=...): Positive Lookahead (asserts what follows).
Understanding Regex Flags
JavaScript uses specific "flags" to alter how the pattern matching behaves.
- Global (
g):- Behavior: Finds all matches in the text, rather than stopping after the first one.
- Use Case: Extracting every email address from a document.
- Multi-line (
m):- Behavior: Changes
^and$to match the start/end of lines, not just the start/end of the whole string. - Use Case: Parsing data that is formatted line-by-line (like CSVs or Logs).
- Behavior: Changes
- Insensitive (
i):- Behavior: Ignores case sensitivity.
- Use Case: Matching "Error", "error", and "ERROR" equally.
- Single-line / DotAll (
s):- Behavior: Allows the dot (
.) to match newlines (\n). - Use Case: Matching content that spans multiple lines, such as HTML blocks
<div>...</div>.
- Behavior: Allows the dot (
- Unicode (
u):- Behavior: Enables full Unicode support, treating surrogate pairs as single characters.
- Use Case: Correctly matching Emojis (e.g.,
💩) or complex non-Latin scripts.