Regex Lab 🧪 — Regex Tester & Validator avatar

Regex Lab 🧪 — Regex Tester & Validator

Pricing

from $0.008 / actor start

Go to Apify Store
Regex Lab 🧪 — Regex Tester & Validator

Regex Lab 🧪 — Regex Tester & Validator

Interactive regex testing tool supporting findall, match, search, split, and sub (replace) modes. Test patterns against sample text, view full match details, capture groups, named groups, and detailed error messages for invalid patterns.

Pricing

from $0.008 / actor start

Rating

0.0

(0)

Developer

Perry AY

Perry AY

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

a day ago

Last modified

Categories

Share

Regex Lab 🧪 — Regex Tester, Validator & Debugger

Test regular expressions against sample text with 5 operation modes, capture group extraction, named group support, flag configuration, and comprehensive error reporting.

Regular expressions are powerful but notoriously difficult to get right. A single misplaced metacharacter can turn a working pattern into a silent failure. Regex Lab gives you a structured debugging environment: compile your pattern, run it against test text in one of five modes, and inspect every detail of the result — match positions, capture groups, named groups, and syntax errors with precise line and column numbers.

Choose from findall (all non-overlapping matches), match (match from the start of the string), search (first match anywhere), split (divide text into parts at each match), or sub (replace matches with placeholder text). Configure any combination of regex flags (i ignorecase, m multiline, s dotall, x verbose, u unicode, a ascii). Named capture groups using (?P<name>...) syntax are fully supported with automatic detection and extraction.


✨ Features

  • 5 operation modesfindall returns all non-overlapping matches, match checks from the start of the string, search finds the first match anywhere, split divides text at match boundaries, and sub replaces matches with configurable text
  • Named capture group support — Full support for Python regex named groups ((?P<name>...) syntax) with automatic detection, extraction, and groupdict output
  • Regex flag configuration — Combine any of 6 regex flags: i (IGNORECASE), m (MULTILINE), s (DOTALL), x (VERBOSE), u (UNICODE), a (ASCII) — passed as a simple string like "ims"
  • Detailed match information — Every match includes the matched text, start and end positions (span), and capture group values — enabling precise debugging of complex patterns
  • Syntax error reporting — Invalid patterns return an error object with the error message, and when available, the exact position, line number, and column number of the syntax error
  • Pattern metadata — Each result includes total group count, named group keys, and whether named groups are present — helpful for understanding pattern structure at a glance
  • Memory-safe output — Match details are limited to 100 entries to prevent excessive output sizes, while the full results arrays can contain any number of matches
  • Zero configuration — No setup, no databases, no dependencies beyond the pattern and text. Just send your regex and see the results

🚀 Quick Start

Find All Matches (findall)

Input:

{
"pattern": "\\d+",
"text": "Contact: 555-1234, 555-5678\nOrders: #A100, #B200",
"mode": "findall"
}

Response:

{
"pattern": "\\d+",
"flags": "",
"mode": "findall",
"text_length": 50,
"groups": 0,
"named_groups": [],
"has_named_groups": false,
"matches": ["555", "1234", "555", "5678", "100", "200"],
"count": 6,
"match_details": [
{ "text": "555", "span": [23, 26] },
{ "text": "1234", "span": [27, 31] },
{ "text": "555", "span": [33, 36] },
{ "text": "5678", "span": [37, 41] },
{ "text": "100", "span": [51, 54] },
{ "text": "200", "span": [57, 60] }
]
}

Search with Named Groups (search)

Input:

{
"pattern": "Hello (?P<name>\\w+)",
"text": "Hello world! Hello regex!",
"mode": "search"
}

Response:

{
"pattern": "Hello (?P<name>\\w+)",
"flags": "",
"mode": "search",
"text_length": 24,
"groups": 1,
"named_groups": ["name"],
"has_named_groups": true,
"matched": true,
"span": [0, 11],
"matched_text": "Hello world",
"groups": ["world"],
"groupdict": { "name": "world" }
}

Replace Matches (sub)

Input:

{
"pattern": "\\d{3}-\\d{4}",
"text": "Call 555-1234 or 555-5678 for help.",
"mode": "sub"
}

Response:

{
"pattern": "\\d{3}-\\d{4}",
"flags": "",
"mode": "sub",
"text_length": 40,
"groups": 0,
"named_groups": [],
"has_named_groups": false,
"replacement": "***",
"new_text": "Call *** or *** for help.",
"replacements": 2
}

Split Text (split)

Input:

{
"pattern": "[,\\s]+",
"text": "apple, banana, cherry, date",
"mode": "split"
}

Response:

{
"pattern": "[,\\s]+",
"flags": "",
"mode": "split",
"text_length": 26,
"groups": 0,
"named_groups": [],
"has_named_groups": false,
"parts": ["apple", "banana", "cherry", "date"],
"count": 4
}

Match from Start (match)

Input:

{
"pattern": "\\d{3}",
"text": "123-456-7890",
"mode": "match"
}

Response:

{
"pattern": "\\d{3}",
"flags": "",
"mode": "match",
"text_length": 11,
"groups": 0,
"named_groups": [],
"has_named_groups": false,
"matched": true,
"span": [0, 3],
"matched_text": "123",
"groups": [],
"groupdict": {}
}

Invalid Pattern — Error Reporting

Input:

{
"pattern": "[unclosed",
"text": "test",
"mode": "findall"
}

Response:

{
"pattern": "[unclosed",
"flags": "",
"mode": "findall",
"text_length": 4,
"error": {
"message": "unterminated character set at position 0",
"pos": 0,
"lineno": 1,
"colno": 1
}
}

📋 Input Parameters

ParameterTypeDefaultDescription
patternstring(required)Regular expression pattern to compile and test. Should be a valid Python regex.
textstring(required)Sample text to test the pattern against.
modestring"findall"Operation mode: findall, match, search, split, or sub.
flagsstring""Regex flag characters. Combine any of: i (ignorecase), m (multiline), s (dotall), x (verbose), u (unicode), a (ascii).

Operation Modes

ModeDescriptionOutput
findallFind all non-overlapping matches of the pattern in the textArray of match strings, count, and match detail with span positions
matchCheck if the pattern matches from the very beginning of the textBoolean matched, span, matched text, groups, and groupdict
searchFind the first occurrence of the pattern anywhere in the textBoolean matched, span, matched text, groups, and groupdict
splitSplit the text into parts at each match boundaryArray of parts and count
subReplace all matches with placeholder text (***)New text string and replacement count

Regex Flags

Flag CharacterPython FlagEffect
ire.IGNORECASEPerform case-insensitive matching
mre.MULTILINE^ and $ match start/end of each line (not just string)
sre.DOTALL. matches any character including newline
xre.VERBOSEAllow whitespace and comments in pattern for readability
ure.UNICODEUnicode matching (Python 3 default)
are.ASCIIRestrict \w, \d, \b, etc. to ASCII-only matching

📤 Output Format

Common Fields (all modes)

FieldTypeDescription
patternstringThe regex pattern that was tested
flagsstringThe flag characters that were applied
modestringThe operation mode used
text_lengthintegerLength of the test text in characters
groupsintegerNumber of capture groups in the pattern
named_groupsarrayList of named group keys (e.g., ["name", "email"])
has_named_groupsbooleanWhether the pattern contains named capture groups
errorobjectError object (only present on compile errors): message, pos, lineno, colno

Mode-Specific Fields

findall Mode

FieldTypeDescription
matchesarrayArray of all matched strings (flattened if multiple groups). Limited to practical output size.
countintegerTotal number of matches found
match_detailsarrayArray of detail objects with text (matched string) and span (start/end positions). Limited to 100 entries.

match and search Modes

FieldTypeDescription
matchedbooleanWhether a match was found
spanarrayStart and end positions of the match: [start, end]
matched_textstringThe text that was matched
groupsarrayTuple of captured group values (empty if no groups)
groupdictobjectDictionary of named group values (empty if no named groups)

split Mode

FieldTypeDescription
partsarrayArray of text parts after splitting
countintegerNumber of parts

sub Mode

FieldTypeDescription
replacementstringThe replacement string used ("***")
new_textstringThe text after all replacements
replacementsintegerNumber of replacements performed

📖 Usage Examples

cURL (Apify API)

# Find all email addresses
curl -X POST "https://api.apify.com/v2/acts/perryay~regex-lab/runs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"text": "Contact us at support@example.com or sales@example.org",
"mode": "findall"
}'
# Case-insensitive search
curl -X POST "https://api.apify.com/v2/acts/perryay~regex-lab/runs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"pattern": "hello",
"text": "Hello World! hello again! HELLO!",
"mode": "findall",
"flags": "i"
}'

Python (Apify SDK)

from apify_client import ApifyClient
client = ApifyClient("YOUR_API_TOKEN")
# Test a regex pattern
result = client.actor("perryay~regex-lab").call(
run_input={
"pattern": r"\b[A-Z][a-z]+\b",
"text": "Alice and Bob went to Paris. Charlie stayed home.",
"mode": "findall",
}
)
dataset = client.dataset(result["defaultDatasetId"]).list_items()
for item in dataset.items:
if item.get("error"):
err = item["error"]
print(f"Regex Error at line {err['lineno']}, col {err['colno']}: {err['message']}")
else:
print(f"Pattern: {item['pattern']}")
print(f"Mode: {item['mode']}")
print(f"Groups: {item['groups']}, Named groups: {item['named_groups']}")
for m in item.get("match_details", []):
print(f" Match '{m['text']}' at position {m['span']}")
print(f"Total matches: {item.get('count', 0)}")

JavaScript / Node.js (Apify SDK)

import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const result = await client.actor('perryay~regex-lab').call({
pattern: '(\\w+)@(\\w+)\\.(\\w+)',
text: 'user@example.com',
mode: 'search',
});
const { items } = await client.dataset(result.defaultDatasetId).listItems();
for (const item of items) {
if (item.matched) {
console.log(`Matched: ${item.matched_text} (position ${item.span})`);
console.log(`Groups: ${item.groups}`);
}
}

🎯 Use Cases

  • Regex development and debugging — Quickly test and iterate on patterns during development without setting up a local Python environment or firing up an interactive shell. See exactly what matches, where, and what groups are captured.
  • Data extraction pipeline prototyping — Before coding a production data extraction pipeline, use Regex Lab to validate that your pattern correctly extracts fields from sample data. Switch between findall and search modes to compare behavior.
  • Log parsing pattern design — Design and test regex patterns for extracting structured data from unstructured log lines (Apache/Nginx access logs, syslog, application logs) before deploying into your log aggregation pipeline.
  • Text sanitization and redaction — Use sub mode to validate that your redaction patterns correctly replace sensitive data (phone numbers, email addresses, credit card numbers) in sample text before rolling out to production pipelines.
  • Input validation pattern testing — Verify that regex patterns intended for form validation, URL routing, or data quality checks behave correctly with valid inputs, edge cases, and malicious payloads.
  • Migration pattern validation — When migrating data between systems, test regex patterns for field extraction, value transformation, and format conversion against sample records before running full-scale migration.
  • Educational demonstrations — Use Regex Lab to teach regex concepts interactively: show how flags change behavior, how capture groups extract sub-matches, and how the different operation modes compare.
  • CI/CD pipeline integration — Automate regex validation as part of your build pipeline. Test critical patterns against known-good and known-bad inputs, and fail the build if expected matches aren't found or unexpected matches appear.

❓ FAQ

Q: What regex engine does this use? A: Python's re module, which implements Perl-compatible regex with some Python-specific extensions. It supports all standard features: character classes, quantifiers, alternation, groups, lookahead/lookbehind, backreferences, and named groups.

Q: Are lookahead and lookbehind assertions supported? A: Yes. Python's re module supports positive lookahead ((?=...)), negative lookahead ((?!...)), positive lookbehind ((?<=...)), and negative lookbehind ((?<!...)). Variable-length lookbehind is supported in Python 3.x (unlike some other regex engines).

Q: What is the difference between match and search modes? A: match checks if the pattern matches starting at position 0 of the text (the beginning). search scans through the entire text and returns the first match anywhere. If you want to find all occurrences, use findall.

Q: How are named capture groups displayed? A: Named groups (defined with (?P<name>...) syntax) are listed in the named_groups array. In match and search modes, their values appear in the groupdict object. The groups field shows the total count of both named and unnamed capture groups.

Q: What happens if my pattern is invalid? A: The actor returns an error object with the Python regex error message, and when available, the exact character position (pos), line number (lineno), and column number (colno) where the error occurred. This makes debugging invalid patterns straightforward.

Q: What does sub mode use as the replacement text? A: By default, sub mode replaces all matches with "***". The replacement text is fixed and cannot be customized in the current version. Use sub mode to verify that your pattern correctly identifies all intended matches and to see the transformation result.

Q: Are backreferences supported in the pattern? A: Yes. Backreferences (\1, \2, etc.) and named backreferences ((?P=name)) are supported in the pattern itself. However, the replacement text in sub mode uses a fixed string (***) and does not currently support backreference expansion in the replacement.

Q: Is there a limit on input text size? A: The actor processes text of any length, but match details are capped at 100 entries and the full matches array may be truncated for very long texts. This prevents excessive output sizes while still giving you complete match coverage.

Q: Can I use this actor with binary or non-UTF-8 data? A: No. The actor expects string input. Binary data or encoded content should be decoded to a string before passing to the actor.

🛠 Tips & Best Practices

  • Start with search mode for pattern discovery — When building a new pattern, use search mode first to confirm your pattern finds something. Once it matches, switch to findall to find all occurrences, then match to verify anchoring behavior.
  • Use findall with groups to extract structured data — When you need to extract specific parts from each match (e.g., name, email, and domain separately), use capture groups in your pattern. The matches array will contain tuples of captured values for each match.
  • Test edge cases explicitly — Always test your pattern against empty strings, very long strings, strings with special characters, strings with newlines (use flag s for dotall), and strings that should not match. The text field accepts any content.
  • Use verbose mode (x) for complex patterns — Complex regex patterns can be hard to read. Add x to your flags and add whitespace and comments within the pattern for readability. The verbose flag ignores whitespace and allows inline comments with #.
  • Debug with span positions — The span values ([start, end]) show the exact character positions of each match. Use these to verify your pattern isn't matching unexpected parts of the input. A span of [6, 9] means characters at indexes 6, 7, and 8 (zero-indexed).
  • Combine flags strategically — Common flag combinations: "i" for case-insensitive search, "im" for case-insensitive multiline matching (useful for log parsing), "is" for case-insensitive dotall (match across lines). Test each combination to ensure expected behavior.
  • Remember to escape in JSON — When sending patterns via the Apify API (JSON), backslashes must be escaped: \d becomes \\d, \w+ becomes \\w+. If you're testing the actor from the Apify Console UI, the JSON editor handles this automatically.
  • Validate with match mode for strict inputs — Use match mode when you need to validate that an entire string conforms to a pattern (e.g., a phone number field, an email format). match requires the pattern to match from the very beginning.

🧪 Pattern Development Workflow

A recommended workflow for developing regex patterns with Regex Lab:

1. Write initial pattern → call actor with search mode
2. Match found? ──YES──→ Check matched text and span
↓ NO ↓ correct
3. Fix pattern syntax 3. Switch to findall mode
(use error position, → check all matches
line, column info) ↓ correct
4. Add capture groups
test search mode for groups
↓ correct
5. Test with expected non-matches
→ confirm no false positives
↓ validated
6. Use in production pipeline

⚙️ Regex Feature Support

FeatureSupportExample
Character classes[a-z], [^0-9]
Shorthand classes\d, \w, \s, \D, \W, \S
Quantifiers+, *, ?, {3}, {2,5}
Greedy/lazy quantifiers.*, .*?, .+?
Alternationcat|dog|bird
Anchors^, $, \b, \B
Grouping(...), (?:...)
Named groups(?P<name>...)
Backreferences\1, \2, (?P=name)
Lookahead(?=...), (?!...)
Lookbehind(?<=...), (?<!...)
Atomic groups(?>...)
Flags inline(?i), (?m), (?s)
Conditional patterns(?(condition)yes|no)

Check out other developer utilities by perryay:

ToolDescription
JSON StudioFormat, validate, transform, and diff JSON data with 8 operation modes
QR CraftGenerate high-quality QR codes in PNG or SVG, batch up to 50
UUID LabGenerate UUID v4/v7, NanoID, Short ID, and ULID identifiers
Domain IntelWHOIS, DNS, and SSL lookup for domain intelligence
Meta MateExtract Open Graph, Twitter Cards, and JSON-LD metadata
IP GeoMulti-provider IP geolocation with ISP detection
URL HealthCheck URL accessibility, redirects, and SSL health
PW ForgeGenerate secure passwords with entropy calculation
TZ MateConvert timezones and check DST offsets
Regex LabTest and debug regular expressions online
Brand Monitor LiteTrack brand mentions across multiple URLs
Link Quality AnalyzerDetect broken links and audit link quality
Mock Data GeneratorGenerate realistic test data for development
HTML to MarkdownConvert web pages or HTML to clean Markdown
SSL Cert InspectorDeep SSL/TLS certificate analysis with scoring