Skip to main content

Regex Tester

Test and debug your regular expressions online

An untested regex breaks silently in production. Paste your pattern and test text below. Matches, capture groups and byte positions appear in seconds.

Options

Secure RE2 engine

RE2 guarantees linear execution time. No risk of ReDoS, even with complex patterns.

Detailed capture groups

Named and indexed groups displayed with their exact byte positions in the source text.

4 configurable flags

Case insensitive, multiline, dot-all and non-greedy. Toggle with a single click before testing.

Instant results

Up to 1,000 matches analyzed in real time. Precise byte positions for every match.

Native UTF-8

The pattern is evaluated on UTF-8 text. Accents, emojis and special characters are fully supported.

Why test your regex online?

A regular expression that works in your IDE can fail in production. Syntax differences between engines, Unicode edge cases and missing flags cause silent data loss. Testing online with the target engine eliminates these risks before deployment.

Three reasons to test before shipping:

  • Catch engine-specific failures early. RE2 rejects lookahead and backreferences. A pattern valid in JavaScript or Python will silently fail in Go or Google infrastructure.
  • Debug capture groups visually. Named groups, byte positions and match boundaries are hard to inspect from a terminal. A visual tester exposes every detail.
  • Prevent ReDoS vulnerabilities. Untested PCRE patterns with nested quantifiers can freeze a server for minutes. RE2 eliminates this risk by design.

How to use the regex tester in 3 steps

Step 1: Enter the pattern

Type your regular expression in the dedicated field. Example for extracting an SPF domain:

include:(?P<domain>[a-z0-9._-]+)

Step 2: Paste your test text

Paste the text you want to test your regex against:

v=spf1 include:_spf.captaindns.com include:spf.protection.outlook.com ~all

Enable flags if needed: case insensitive, multiline, dot-all or non-greedy.

Step 3: Read the results

Each match displays its byte position, matched content and capture groups. Named groups are identified by their label. Verify that every expected substring is captured before integrating the pattern.


What is a regular expression?

A regular expression (regex) is a pattern that describes a set of strings. Regex engines scan input text and return every substring that matches the pattern. Developers use regex to search, validate and extract structured data from unstructured text.

Fundamental components:

ElementSyntaxExampleResult
Literal characteraabc in "abcdef"matches "abc"
Character class[a-z][0-9]+ in "port 443"matches "443"
Quantifier+, *, ?a+ in "aab"matches "aa"
Capture group(...)(abc) in "xabcx"captures "abc"
Anchor^, $^v=spf1matches at line start
Alternationa|bcat|dog in "my cat"matches "cat"

Concrete example with named groups:

(?P<protocol>https?)://(?P<domain>[a-z0-9.-]+)

Applied to https://captaindns.com/tools:

  • Group protocol: https
  • Group domain: captaindns.com

RE2 vs PCRE syntax: the differences

RE2 is the regex engine developed by Google and used natively by Go. PCRE (Perl Compatible Regular Expressions) powers PHP, Python's re module and most JavaScript engines. The two engines differ in capability and safety guarantees.

FeatureRE2PCRE
Execution time guaranteeLinear O(n)Potentially exponential
Lookahead/lookbehindNot supportedSupported
Backreferences (\1)Not supportedSupported
Possessive quantifiersNot supportedSupported
Named groups(?P<name>...)(?P<name>...) or (?<name>...)
Global non-greedy flag(?U)Non-standard
UnicodeNative UTF-8Via u flag

Why RE2 matters for web services: the linear time guarantee eliminates ReDoS attacks entirely. A malicious input that freezes a PCRE engine for minutes executes in milliseconds on RE2. This is why Google, Cloudflare and CaptainDNS use RE2 for public-facing regex processing.


Real-world use cases

Validate an SPF record

Situation: You need to verify that your SPF record contains the correct include mechanisms.

Diagnosis: Test the pattern include:([a-z0-9._-]+) against the value of your TXT record. The tool lists each included domain with its byte position.

Action: Compare extracted domains with your expected list. A missing or misspelled include causes SPF alignment failures and email delivery issues.

Extract email addresses from text

Situation: You need to extract all email addresses from a configuration file or log dump.

Diagnosis: Use the pattern [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} with the case insensitive flag enabled. Each email found appears as a separate match with its position.

Action: Verify that each extracted address is legitimate. False positives from encoded strings or comments are common.

Debug a log parsing pattern

Situation: Your log parser is not capturing timestamps correctly.

Diagnosis: Test your pattern with named groups: (?P<date>\d{4}-\d{2}-\d{2}) (?P<time>\d{2}:\d{2}:\d{2}). Verify that the date and time groups capture the correct substrings.

Action: Adjust quantifiers or character classes until every group extracts the expected values. Test with edge cases: midnight timestamps, single-digit months, log entries with milliseconds.


Common syntax errors

ErrorCauseFix
error parsing regexpInvalid syntax (unclosed parenthesis, quantifier without target)Check that every ( has a matching )
invalid escape sequenceEscape sequence not recognized by RE2Use \\ for a literal backslash
invalid named captureIncorrect named group syntaxUse (?P<name>...) not (?<name>...)
invalid repeat countQuantifier value out of rangeReduce the repetition bound (max 1,000)
No results returnedPattern too restrictive or wrong flagEnable case insensitive or dot-all flag

❓ FAQ - Frequently asked questions

Q: Why is my regex not finding any matches?

A: Check three things. First, RE2 does not support lookahead, lookbehind or backreferences. Second, enable the "case insensitive" flag if your text contains mixed case. Third, verify that special characters in your pattern are properly escaped.


Q: What is RE2 syntax?

A: RE2 is the regex engine developed by Google and used natively by Go. It guarantees linear execution time relative to input size. Unlike PCRE, RE2 is immune to ReDoS attacks.


Q: What regex flags are available?

A: Four flags: case insensitive (i), multiline (m), dot matches newline (s) and non-greedy (U). Each flag modifies the engine behavior for the entire pattern.


Q: What is the text size limit?

A: The pattern is limited to 10 KB. The test text is limited to 1 MB. The maximum number of returned matches is 1,000. These limits protect the service against abuse.


Q: What is a named capture group?

A: A named group uses the syntax (?P<name>...) in RE2. It lets you identify a captured substring by name instead of numeric index. This improves readability in patterns with multiple groups.


Q: Is RE2 compatible with JavaScript regex?

A: Partially. RE2 supports character classes, quantifiers and groups. It does not support lookahead, lookbehind, backreferences or possessive quantifiers. Test your JavaScript patterns here to identify incompatibilities before porting to Go.


Q: Is the data stored?

A: No. Your pattern and text are sent to the CaptainDNS API for processing, then deleted immediately. No content is stored, cached or logged.


Complementary tools

ToolUse
Hash GeneratorCompute the hash of text matched by your regex
Base64 Encoder/DecoderDecode Base64 text before testing with a regex
URL Encoder/DecoderDecode encoded URLs before regex extraction
Case ConverterNormalize text case before testing
SPF InspectorCheck SPF records you validate with regex

Useful resources


Privacy commitment

Your pattern and text are sent to the CaptainDNS API solely to execute the regex test. No content is stored after processing. No data is shared with third parties. Only anonymous technical metrics are logged: pattern size, match count and processing time.