Regex tester online free — test regular expressions instantly

Test JavaScript regular expressions with live matches and captured groups in your browser.

Matches found: 7
«Paste» «text» «here» to «test» «regular» «expressions» «quickly».
Match list
1. "Paste" at index 0
2. "text" at index 6
3. "here" at index 11
4. "test" at index 19
5. "regular" at index 24
6. "expressions" at index 32
7. "quickly" at index 44

About the Regex Tester

Test a JavaScript regular expression against sample text and see every match wrapped in « » markers, plus a numbered list of matches with their character index. Results update on each keystroke, and invalid patterns show the engine's error message. The engine is your browser's, so behavior matches JavaScript and Node.js. The starting pattern \b\w{4,}\b matches every word of four or more letters.

How to use the Regex Tester

  1. Type your pattern into Pattern without the surrounding slashes (\d+, not /\d+/).
  2. Enter flags in Flags (g i m s u y). With g every match is listed; without g only the first match is shown, as in JavaScript.
  3. Paste sample text into Test text.
  4. Read Matches found, the highlighted text, and the Match list with each match's index.

Worked example: pulling ticket IDs from a commit message

Pattern \b[A-Z]{2,}-\d+\b finds Jira-style keys: two or more capital letters, a hyphen and digits. With flags g it skips the lowercase api-77; adding i matches it too.

Test text
Closes WEB-412, relates to api-77 and OPS-9.
Flags: g
Matches found: 2
Closes «WEB-412», relates to api-77 and «OPS-9».

1. "WEB-412" at index 7
2. "OPS-9" at index 38
Flags: gi
Matches found: 3
Closes «WEB-412», relates to «api-77» and «OPS-9».

1. "WEB-412" at index 7
2. "api-77" at index 27
3. "OPS-9" at index 38

Errors you might see and what they mean

The index in the match list counts UTF-16 code units from 0, which is what JavaScript's string.slice() and indexOf() use. An emoji before a match shifts its index by 2, not 1. If you are matching inside URLs, decode percent-encoded text first so %20 and friends do not hide your matches.

MessageCauseFix
Invalid flags supplied to RegExp constructorUnknown or repeated flag, such as gg or xUse only g, i, m, s, u, y, each once
Unterminated group / Unmatched ')'Parentheses do not balanceCount ( and ); escape literal ones as \( and \)
Nothing to repeatA quantifier with nothing before it, such as +abc or a lone ?Escape it (\+, \?) or put a character before it
Invalid escape (with the u flag)Unicode mode rejects unnecessary escapes like \-Remove the backslash or drop the u flag

Regular expression syntax quick reference

A regular expression is a pattern that describes a set of strings. The most common elements: . matches any character except newline; * means zero or more; + means one or more; ? means zero or one. Character classes like [a-z] match any lowercase letter; [^0-9] matches anything that is not a digit. ^ anchors to the start of a line; $ anchors to the end.

Groups and alternation: parentheses () create capture groups — matched text can be referenced with $1, $2, etc. in replacements. (?:...) is a non-capturing group. The | operator means OR: cat|dog matches either "cat" or "dog". Quantifiers can be made lazy (match as few characters as possible) by appending ?: .*? matches the shortest possible sequence.

Common regex flags

Flags modify how a pattern matches. The g (global) flag finds all matches instead of stopping at the first. The i (case-insensitive) flag makes uppercase and lowercase letters interchangeable. The m (multiline) flag changes ^ and $ to match the start and end of each line rather than the whole string. The s (dotAll) flag makes . match newline characters too.

In JavaScript, flags are appended after the closing slash: /pattern/gi. The u flag enables full Unicode mode, treating the string as a sequence of Unicode code points rather than UTF-16 code units — important for matching emoji and non-BMP characters correctly.

Patterns for common validation tasks

Email (simplified): /^[^\s@]+@[^\s@]+\.[^\s@]+$/. This is not RFC 5322 compliant but catches most real-world valid emails. Full RFC compliance requires a large regex — use a library for production validation.

URL: /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/. Phone (US): /^\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/. ISO date: /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.

Lookaheads and lookbehinds let you match text only when followed or preceded by a pattern, without including that context in the match. Positive lookahead: \d+(?= dollars) matches digits followed by " dollars". Negative lookbehind: (?<!un)happy matches "happy" not preceded by "un".

Performance pitfalls: catastrophic backtracking

Some regex patterns cause exponential backtracking on certain inputs, making the engine appear to hang. The classic example is (a+)+ applied to a long string of "a" characters followed by a character that does not match. The engine tries all possible groupings before failing — exponential work for a linear-length string.

To avoid this: prefer atomic groups or possessive quantifiers where your engine supports them. Avoid nested quantifiers ((a*)*). Use anchors (^ and $) to fail fast. When validating untrusted input with regex in a server context, set a timeout or use a linear-time regex engine. The browser context on this page is forgiving — a slow pattern will just freeze the page temporarily rather than causing a server outage.

Regex Tester: frequently asked questions

What regex flags are supported?
All JavaScript regex flags: g (global), i (case insensitive), m (multiline), s (dotAll), u (unicode), y (sticky). Type the flags you want into the Flags field; keep g in the list, since the match list finds all matches.
Can I test capture groups?
The match list shows each full match and its position. Capture groups still affect what matches, but their individual values are not listed separately, so for group-by-group output test in your code or browser console.
Does this work for other programming languages?
This tool uses JavaScript regex engine. While most basic patterns work across languages, advanced features like lookbehinds, named groups, and flags may differ. Test in your target language for production code.
Is my test data sent to servers?
No. Pattern matching runs entirely in your browser with JavaScript RegExp. Your patterns and test strings never leave your device.