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:
| Element | Syntax | Example | Result |
|---|---|---|---|
| Literal character | a | abc 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=spf1 | matches at line start |
| Alternation | a|b | cat|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.
| Feature | RE2 | PCRE |
|---|---|---|
| Execution time guarantee | Linear O(n) | Potentially exponential |
| Lookahead/lookbehind | Not supported | Supported |
Backreferences (\1) | Not supported | Supported |
| Possessive quantifiers | Not supported | Supported |
| Named groups | (?P<name>...) | (?P<name>...) or (?<name>...) |
| Global non-greedy flag | (?U) | Non-standard |
| Unicode | Native UTF-8 | Via 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
| Error | Cause | Fix |
|---|---|---|
error parsing regexp | Invalid syntax (unclosed parenthesis, quantifier without target) | Check that every ( has a matching ) |
invalid escape sequence | Escape sequence not recognized by RE2 | Use \\ for a literal backslash |
invalid named capture | Incorrect named group syntax | Use (?P<name>...) not (?<name>...) |
invalid repeat count | Quantifier value out of range | Reduce the repetition bound (max 1,000) |
| No results returned | Pattern too restrictive or wrong flag | Enable 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
| Tool | Use |
|---|---|
| Hash Generator | Compute the hash of text matched by your regex |
| Base64 Encoder/Decoder | Decode Base64 text before testing with a regex |
| URL Encoder/Decoder | Decode encoded URLs before regex extraction |
| Case Converter | Normalize text case before testing |
| SPF Inspector | Check SPF records you validate with regex |
Useful resources
- RE2 syntax reference (complete RE2 engine syntax)
- RFC 7208 - SPF (SPF record format testable with regex)
- Regular-Expressions.info (comprehensive regular expressions tutorial)
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.