Updated 2026-01

Regex Tester

Free online regex tester using PCRE syntax. Test match, find groups, and run replacement. Highlights matches in your test string with capture group breakdown.

Regex Tester

/

Flags: g (global), i (case-insensitive), m (multiline), s (dotall), u (Unicode), v (unicodeSets — ES2024)

Common patterns

Share with friends

How to use

  1. 1 Enter your regex pattern in the pattern field. No leading or trailing slashes — just the pattern.
  2. 2 Set flags: i (case-insensitive), m (^/$ match line breaks), s (. matches newline).
  3. 3 Paste the test string into the input box. Matches highlight in real time.
  4. 4 Switch to Replace mode and enter a replacement string with $1, $2 backreferences to use capture groups.
  5. 5 For complex regex, build incrementally — write the simplest pattern that matches one example, then expand.

FAQ

Q How do I write a regex for an email address?

A practical pattern is <code>[\w.+-]+@[\w-]+\.[\w.-]+</code>. RFC 5322-compliant email regex is enormously complex (over 6,000 characters in the strictest form). For form validation use the simpler pattern plus an actual confirmation email — that proves the address works.

Q What does \d mean in regex?

It matches any digit 0–9. Equivalent to <code>[0-9]</code>. Related shortcuts: <code>\w</code> = word character (a-z, A-Z, 0-9, underscore), <code>\s</code> = whitespace (space, tab, newline). Capitalize for negation: <code>\D</code> = non-digit, <code>\W</code> = non-word, <code>\S</code> = non-whitespace.

Q Why doesn't my regex match across line breaks?

By default, <code>.</code> does not match newline characters and <code>^</code>/<code>$</code> match only at start/end of the whole string. Enable the <code>s</code> flag (dotall) to make <code>.</code> match newline. Enable <code>m</code> (multiline) to make <code>^</code> and <code>$</code> match at every line break.

Q What is the difference between (.*) and (.*?)?

They differ in greediness. <code>(.*)</code> is greedy — matches as much as possible. <code>(.*?)</code> is lazy — matches as little as possible. For HTML <code>&lt;.*&gt;</code> matches the entire string from first &lt; to last &gt;; <code>&lt;.*?&gt;</code> matches each tag individually.

Q How do I extract phone numbers from text?

Use <code>\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}</code> to match common US formats: 555-555-1234, (555) 555-1234, 555.555.1234, 5555551234. For international numbers add an optional <code>\+?\d{1,3}[-. ]?</code> prefix. The North American Numbering Plan reserves 555-01XX for fictional use, useful for test data.

Q Can regex parse HTML?

Not reliably — HTML is not a regular language. Regex works for trivial cases (extracting one specific simple tag) but breaks on nested elements, attributes with spaces, and edge cases. Use a real HTML parser: BeautifulSoup (Python), Cheerio (Node.js), or DOMParser (browser).

Q What is catastrophic backtracking and how do I avoid it?

It's exponential slowdown caused by nested quantifiers like <code>(a+)+b</code> on inputs that don't end with b. The regex engine tries all combinations and can hang for seconds on inputs of just 30 characters. Avoid nested quantifiers, use possessive quantifiers (<code>++</code>) when supported, or atomic groups <code>(?&gt;...)</code>.

Q How do I make a regex case-insensitive?

Add the <code>i</code> flag. In JavaScript: <code>/hello/i</code>. In Python: <code>re.compile(r'hello', re.I)</code>. In PCRE: pattern modifier <code>(?i)</code> at the start of the pattern. This calculator's flags toggle handles all PCRE flags: i, m, s, u, x.