Textpire

Regex Tester

Test regular expressions against sample text and see all matches highlighted.

Test text
Pattern
//

Matches will be highlighted here…

Share This Tool

I've Broken Production Three Times with a Regex I Thought I'd Tested

The first time it happened, I was stripping HTML tags from user input with a regex that worked perfectly in my console. In production, some user submitted content with a self-closing tag followed by a comment and the pattern went into catastrophic backtracking. The page timed out. I learned my lesson: test regex against real, messy data β€” not clean examples you made up yourself.

A real-time regex tester changes how you work with regular expressions. Instead of writing a pattern, deploying it, and finding out at runtime that it matches the wrong things, you test it against actual input first. You see match counts, highlighted matches, capture groups, and the result of replacements β€” all updating live as you type.

How to Use This

Paste your test text in the top box. Type your pattern in the pattern field β€” without slashes, just the expression itself. Select the flags you need. Matches appear highlighted in real time. The match count shows in the badge next to the pattern field. If your pattern has a syntax error, the error message appears immediately so you're not guessing what's wrong.

For capture groups, the match list below the highlighted text shows each group separately. If you're using the tool to test an extraction pattern β€” pulling email addresses, URLs, or phone numbers from text β€” this is where you confirm the groups are capturing what you think they are.

Switch to the Replace tab to test substitutions. Type your replacement string in the replacement field β€” use $1, $2, etc. to reference capture groups. The output updates live so you can see exactly what the replacement produces before you put it in your code.

Flags Worth Understanding

The global flag (g) finds all matches. Without it, only the first match is returned. This is probably the most common mistake β€” testing without global and wondering why only one result comes back. The case-insensitive flag (i) makes the match ignore uppercase and lowercase differences. The multiline flag (m) changes what the caret and dollar sign match β€” with multiline on, they match the start and end of each line instead of just the start and end of the entire string. This matters a lot for patterns that use anchors.

Patterns I Reach For Most Often

Extracting emails: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}. Matching URLs: https?://[^s]+. Matching whole words only: wrap your term in  word boundary anchors. Removing extra whitespace: s+ replaced with a single space. Validating hex colors: #([a-fA-F0-9]{6}|[a-fA-F0-9]{3}).

If you end up extracting a lot of text patterns from a document, the Email Extractor and Keyword Extractor tools handle those specific cases with no regex needed. And for replacing text at scale without regex complexity, Find and Replace is often the simpler choice.

Why Browser-Based

I test regex against real data, and real data is often sensitive β€” API responses, log files, user records. Running the test locally in your browser means nothing gets sent anywhere. You can test against actual production data without worrying about what you're transmitting.

Frequently Asked Questions

What regex flavor does this use?

JavaScript RegExp (ECMA-262). This is compatible with Node.js, browser JavaScript, and close enough to most other flavors for practical use. Key differences from PCRE: no lookbehinds in older environments, no possessive quantifiers, and d matches only ASCII digits.

What does the global flag actually do?

Without the global flag (g), JavaScript regex stops after the first match. With it, the engine continues scanning and returns all matches. This is why you almost always want global enabled β€” the default in this tool.

How do I match literal special characters like dots or brackets?

Escape them with a backslash. A literal dot is ., a literal opening bracket is [, a literal parenthesis is (. Without escaping, . matches any character and brackets start a character class.

Why does my pattern cause a timeout or freeze?

Catastrophic backtracking. Patterns like (a+)+ on input that doesn't match can cause exponential execution time. This happens when nested quantifiers create ambiguous paths the engine has to explore exhaustively. If you're hitting this, simplify the nested quantifiers or use atomic grouping if your engine supports it.

Can I test multiline input?

Yes β€” paste text with newlines directly into the input area. With the multiline flag (m) enabled, ^ and $ match the start and end of each line. Without it, they only match the start and end of the entire string.

Related Tools