Regex Tester

Regex Tester

Regex tester online free. Test regular expressions with live highlighting, flags toggle (g i m s u), and match count. Debug regex patterns instantly in your browser.

0 chars 0 lines
🧪

Regular Expression

Enter your pattern below

/ /g

Pattern Flags

Active flags: /g

📚 Quick Reference

. any char
\d digit
\w word char
\s whitespace
^ start
$ end
* 0 or more
+ 1 or more

Features

  • Live highlighting of all matches as you type
  • Toggle flags: global (g), case-insensitive (i), multiline (m), dotall (s), unicode (u)
  • Detailed match results table with index, length, and capture groups
  • Pattern history saved in localStorage
  • Quick templates: Email, URL, Phone, Date, IP, Hex colors
  • Shareable URL encoding for patterns and test strings
  • Execution time display for performance awareness

Common Use Cases

  • Validate user input formats (emails, phone numbers, postal codes)
  • Extract structured data from raw text
  • Debug complex regular expressions step-by-step
  • Learning and experimenting with regex syntax interactively
  • Generate shareable regex test cases for code reviews

What is a Regular Expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It is a powerful tool for matching, searching, and validating text.

In JavaScript (and most languages), a regex is written between forward slashes: /pattern/flags. The pattern describes what to match, and flags modify how matching is performed (e.g., g for finding all matches, i for case-insensitive).

Regular expressions are used across virtually every programming language and tool — from code editors and command-line tools to database queries and web application validation.

Examples

Valid - Email Address
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Valid - US Phone Number
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
Valid - URL (http/https)
https?://[\w.-]+(?:/[\w./-]*)?
Valid - IPv4 Address
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

Frequently Asked Questions

What do the flags g, i, m, s, u mean?

g (global) — find all matches, not just the first. i (case-insensitive) — ignore uppercase/lowercase. m (multiline) — ^ and $ match start/end of each line. s (dotall) — . matches newline characters too. u (unicode) — enables full Unicode support.

Why does my regex match nothing?

Common causes:

  • A missing g flag when expecting multiple matches
  • Unescaped special characters like ., *, (, ) — use a backslash to escape them
  • Incorrect anchors — ^ anchors to start, $ to end of string (or line with m)

How do I match a literal dot or parenthesis?

Escape it with a backslash: \. matches a literal dot, \( matches a literal opening parenthesis. Without the backslash, . is a wildcard that matches any character except newline.

What is the difference between + and *?

* means "zero or more" — the preceding element can appear any number of times, including zero. + means "one or more" — the preceding element must appear at least once. Use ? for "zero or one" (optional).

Are regex patterns case-sensitive by default?

Yes. By default, /hello/ will not match "Hello" or "HELLO". Add the i flag — /hello/i — to make the match case-insensitive.

Can I share a regex test case with someone?

Yes! Use the Share button to copy a URL that encodes your pattern, flags, and test string. Anyone who opens the link will see the same pattern and input pre-loaded.

💡 Tips

  • Start simple: build your pattern incrementally, adding one piece at a time.
  • Use <code>\b</code> (word boundary) to avoid matching substrings inside words — e.g., <code>\bcat\b</code> won't match "catch".
  • Test edge cases: empty strings, very long inputs, special characters, and Unicode characters.
  • Prefer specific character classes over the wildcard <code>.</code> to avoid unexpected matches.
  • For performance-sensitive code, avoid catastrophic backtracking by using atomic groups or possessive quantifiers.
  • Use the <code>g</code> flag with <code>exec()</code> carefully — the regex's <code>lastIndex</code> advances with each call.