30 Claude Prompts That Write Regular Expressions
Describe the pattern in plain English and Claude returns a tested regex, a token-by-token explanation, and pass/fail examples. Prompts for validation, extraction, search-and-replace, log parsing, data cleaning, and gnarly lookarounds. Not "here's a regex, good luck."
In short: This page contains 30 copy-paste ready prompts, organized into 6 categories with a description and pro tip for each. The first 15 prompts are free instantly โ no signup needed. Hand-curated and tested by the AI Academy team.
Validation Patterns
5 promptsRobust Email Address Validator
1/30You are a regex engineer who writes practical, well-tested validation patterns. <context> I need a regular expression to validate email addresses in my app. The output must be a self-contained, ready-to-use regex with an explanation and a test set, so I can paste it in and trust it. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE, .NET] - How strict: [PRACTICAL EVERYDAY EMAILS / RFC-LEANING] - Allow plus-addressing and subdomains: [YES / NO] - Should it be anchored to the whole string: [YES / NO] - Case sensitivity: [CASE-INSENSITIVE / SENSITIVE] </inputs> <task> Write ONE email-validation regex for the specified flavor. Then give a token-by-token breakdown of what each part matches, and provide a test table with at least 8 valid and 8 invalid inputs (including edge cases like leading dots, double dots, missing TLD, plus-addressing, and unicode) each marked PASS or FAIL. </task> <constraints> - Valid, copy-paste-ready syntax for the exact flavor named; no pseudo-regex. - Do not over-engineer toward full RFC 5322 unless RFC-leaning is chosen; state the tradeoff. - Note any flags required (e.g. i, u) explicitly. </constraints> <format> Return the regex in a code block, then the token breakdown, then the test table (Input | Expected | Reason), then one line on how to adjust strictness. </format>
Produces a tested email-validation regex with a token breakdown and a pass/fail test table, ready to use.
Pro tip: Tell Claude the exact language flavor up front (JS vs PCRE vs .NET); anchoring and unicode support differ enough to break a pattern silently.
International Phone Number Validator
2/30You are a regex engineer specializing in input validation. <context> I need a regex to validate phone numbers entered by users. It must be a ready-to-use pattern with an explanation and examples so I can drop it into a form validator. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE] - Formats to accept: [E.G. +COUNTRY CODE, SPACES, DASHES, PARENTHESES, DOTS] - Country scope: [SINGLE COUNTRY / E.164 INTERNATIONAL] - Allow extensions (ext, x): [YES / NO] - Anchored to full string: [YES / NO] </inputs> <task> Write ONE phone-validation regex for the named flavor and scope. Break down each segment (optional country code, separators, digit groups, extension). Provide a test table of at least 8 valid and 8 invalid numbers covering the accepted formats plus common mistakes (too few digits, letters, doubled separators). </task> <constraints> - Valid, copy-paste syntax for the exact flavor; escape characters correctly. - Keep it readable; if it gets long, provide an optional verbose/commented version too. - Be explicit about what it does NOT guarantee (a valid format is not a real, dialable number). </constraints> <format> Return the regex in a code block, then the segment breakdown, then the test table, then one line on tightening it to a specific country. </format>
Generates a phone-number validation regex with a segment breakdown and a pass/fail test set, ready to drop in.
Pro tip: Decide E.164 vs a single-country format before asking; international patterns must be looser and Claude will otherwise reject valid local numbers.
URL and Domain Validator
3/30You are a regex engineer who validates web-facing user input. <context> I need a regex to validate URLs (or bare domains) entered by users. Give me a ready-to-use pattern plus an explanation and examples. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE] - Accept: [FULL URLS ONLY / BARE DOMAINS TOO] - Require scheme: [MUST HAVE http/https / OPTIONAL] - Allow ports, paths, query strings, fragments: [WHICH ONES] - Allow localhost / IP addresses: [YES / NO] </inputs> <task> Write ONE URL-validation regex matching the rules above. Explain each group (scheme, host, TLD, port, path, query, fragment). Provide a test table with at least 8 valid and 8 invalid inputs, including tricky cases (trailing dot, missing TLD, spaces, javascript: scheme, IP hosts). </task> <constraints> - Valid copy-paste syntax for the exact flavor; correct escaping of dots and slashes. - State clearly whether it validates SYNTAX only, not reachability. - If the strict version is unreadable, also give a pragmatic shorter variant. </constraints> <format> Return the regex in a code block, then the group breakdown, then the test table (Input | Expected | Reason), then a note on when to just use a URL parser instead. </format>
Produces a URL/domain validation regex with a group-by-group explanation and edge-case test table, ready to use.
Pro tip: Ask Claude to flag when a real URL parser (like the URL constructor) is safer than regex; for many cases it genuinely is.
Password Strength Rule Enforcer
4/30You are a security-minded regex engineer. <context> I need regex to enforce a password policy at signup. Deliver ready-to-use patterns plus an explanation and a test set. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, .NET] - Rules: [MIN LENGTH, UPPERCASE, LOWERCASE, DIGIT, SPECIAL CHAR, ETC.] - Allowed special characters: [WHICH SET] - Disallow spaces or specific chars: [YES / NO, WHICH] </inputs> <task> Provide the password policy as regex using lookaheads for each requirement, as ONE combined pattern. Explain each lookahead. Then, because a single mega-regex gives poor error messages, also provide the same rules as SEPARATE small regexes (one per rule) so I can show precise feedback. Give a test table of at least 8 passwords marked PASS/FAIL with the failing rule named. </task> <constraints> - Valid copy-paste syntax; lookaheads correct for the named flavor. - Anchor with ^ and $ appropriately; note required flags. - Warn that regex should not be the only password check (recommend a breached-password check too). </constraints> <format> Return the combined regex, then the per-rule regexes in a table (Rule | Regex), then the token breakdown, then the test table. </format>
Delivers a combined password-policy regex plus per-rule patterns for precise feedback, with a test table, ready to use.
Pro tip: Ask for the per-rule regexes, not just the mega-pattern; separate checks let you tell users exactly which rule they failed.
Date, Time, and Postal-Code Formats
5/30You are a regex engineer who validates structured formatted fields. <context> I need regex to validate a specific formatted field (a date, a time, or a postal/ZIP code). Deliver a ready-to-use pattern with explanation and examples. </context> <inputs> - Field type: [DATE / TIME / POSTAL OR ZIP CODE] - Exact format(s) to accept: [E.G. YYYY-MM-DD, DD/MM/YYYY, HH:MM 24H, US ZIP+4, UK POSTCODE] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE] - Reject impossible values: [E.G. MONTH 13, HOUR 25 - YES / NO] </inputs> <task> Write ONE regex for the specified field and format. If rejecting impossible values, encode the ranges (e.g. months 01-12, days 01-31, hours 00-23). Explain each numeric range group. Provide a test table of at least 8 valid and 8 invalid values, including boundary cases (00, 13, 31, 32) and wrong separators. </task> <constraints> - Valid copy-paste syntax for the exact flavor; correct handling of leading zeros. - Be explicit that a syntactically valid date (e.g. 2026-02-30) may still be a non-existent calendar date; recommend a date-library check for that. </constraints> <format> Return the regex in a code block, then the range-by-range breakdown, then the test table, then one line on switching to another accepted format. </format>
Generates a range-aware regex for dates, times, or postal codes with a boundary-case test table, ready to use.
Pro tip: For dates, ask Claude to encode month/day ranges but also warn you that regex can't catch Feb 30 - pair it with a real date parse.
XML tags are just the start. Learn the full Claude workflow.
A growing library of 300+ hands-on AI tutorials covering Claude, ChatGPT, and 50+ tools. New tutorials added every week.
Data Extraction
5 promptsExtract All Emails and URLs From Text
6/30You are a regex engineer who writes reliable extraction patterns. <context> I have a blob of freeform text and need to pull out every email address (or URL) as a list. Deliver a ready-to-use regex with explanation and a runnable snippet. </context> <inputs> - Extract: [EMAILS / URLS / BOTH] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON] - Sample input text: [PASTE A REPRESENTATIVE SNIPPET] - Deduplicate results: [YES / NO] - Keep or strip surrounding punctuation: [DESCRIBE] </inputs> <task> Write a global extraction regex (not anchored) that finds all matches in text. Explain the pattern. Then show a short, complete code snippet in the named language that runs the regex over the sample, deduplicates if requested, and prints the results. Include a list of what it correctly extracts from my sample and any it intentionally skips. </task> <constraints> - Valid copy-paste syntax; global/multiline flags set correctly. - Handle trailing punctuation (e.g. a period after a URL at end of sentence) sensibly. - The code snippet must run as-is with no external dependencies. </constraints> <format> Return the regex, then the breakdown, then the runnable code snippet, then the extracted results from my sample. </format>
Produces a global extraction regex plus a runnable snippet that pulls emails or URLs from text, ready to use.
Pro tip: Paste a real sample of your messy text; Claude tunes the trailing-punctuation handling to what actually appears in your data.
Capture Groups With Named Fields
7/30You are a regex engineer who designs patterns with clean named capture groups. <context> I have structured strings and need to parse each into named fields using one regex with named groups. Deliver a ready-to-use pattern plus a parsing snippet. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, .NET] - Sample lines to parse: [PASTE 3-5 EXAMPLES] - Fields I want captured: [E.G. date, level, user, message] - Any optional fields: [WHICH ONES] </inputs> <task> Write ONE regex using named capture groups for each requested field. Explain each group and why it is shaped that way. Provide a code snippet in the named language that applies the regex to my samples and prints each field by name. Show the parsed output for every sample line I gave. </task> <constraints> - Use the correct named-group syntax for the exact flavor (?<name>...) or (?P<name>...). - Handle optional fields with non-capturing optional groups so absent fields don't break the match. - Valid, copy-paste, runnable code. </constraints> <format> Return the regex, then a table of Group | Meaning, then the runnable snippet, then the parsed fields for each sample. </format>
Generates a named-capture-group regex and a snippet that parses your sample strings into labeled fields, ready to use.
Pro tip: Give 3-5 varied sample lines including ones with missing fields; that's how Claude gets the optional groups right instead of guessing.
Pull Numbers, Prices, and Quantities
8/30You are a regex engineer who extracts numeric data from text. <context> I need to extract numbers, prices, or quantities from messy text (with currency symbols, thousands separators, decimals, units). Deliver a ready-to-use regex with explanation and a snippet. </context> <inputs> - What to extract: [PLAIN NUMBERS / CURRENCY AMOUNTS / QUANTITIES WITH UNITS] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON] - Number style: [1,000.50 / 1.000,50 / BOTH] - Currency symbols or units expected: [E.G. $, EUR, kg, GB] - Sample text: [PASTE A SNIPPET] </inputs> <task> Write a regex that matches the target numeric values, capturing the sign, integer part, thousands separators, decimal part, and any symbol/unit as separate groups. Explain the groups. Provide a snippet that extracts matches from my sample and normalizes each into a plain float (stripping separators). Show the normalized results. </task> <constraints> - Valid copy-paste syntax; handle both comma and dot conventions if requested. - Don't match things like version numbers or dates as prices; explain how you avoid false positives. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the group breakdown, then the normalization snippet, then a table of Raw match | Normalized value from my sample. </format>
Produces a regex and snippet that extract and normalize numbers, prices, or quantities from messy text, ready to use.
Pro tip: State your number style (1,000.50 vs 1.000,50) explicitly; the thousands/decimal separators flip between locales and silently corrupt results.
Scrape Fields From HTML or Markup
9/30You are a regex engineer who extracts values from tag-based markup for quick one-off jobs. <context> I need to pull specific values out of a chunk of HTML or XML (e.g. all href links, alt text, tag contents) for a quick scrape. Deliver a ready-to-use regex with explanation and a snippet. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON] - What to extract: [E.G. HREF VALUES, IMG ALT TEXT, TEXT INSIDE A GIVEN TAG] - Sample markup: [PASTE A REPRESENTATIVE SNIPPET] - Attribute-quote style: [DOUBLE / SINGLE / EITHER] </inputs> <task> Write a regex that extracts the requested values, tolerant of both quote styles and extra attributes/whitespace inside tags. Explain the pattern. Provide a runnable snippet that returns the list of extracted values from my sample. Then clearly state the limits of regex on HTML and recommend a proper parser for anything beyond a one-off. </task> <constraints> - Valid copy-paste syntax; case-insensitive tag matching; non-greedy where needed. - Must NOT claim to parse arbitrary/nested HTML reliably; be honest about the tradeoff. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the breakdown, then the snippet, then the extracted values, then a one-line 'use a DOM parser when...' caveat. </format>
Generates a pragmatic regex and snippet to scrape attributes or tag contents from markup, with honest limits, ready to use.
Pro tip: This is fine for quick one-offs; if the HTML is nested or untrusted, ask Claude for the DOM-parser version instead of fighting regex.
Extract IDs, Hashtags, and Mentions
10/30You are a regex engineer who parses tokens out of social and app text. <context> I need to extract identifier-style tokens from text: hashtags, @mentions, ticket IDs, order numbers, or similar. Deliver a ready-to-use regex with explanation and a snippet. </context> <inputs> - Token type: [HASHTAGS / @MENTIONS / TICKET IDS LIKE JIRA-123 / ORDER NUMBERS / OTHER PATTERN] - Exact shape: [DESCRIBE THE FORMAT, E.G. 2-4 UPPERCASE LETTERS, DASH, DIGITS] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON] - Sample text: [PASTE A SNIPPET] </inputs> <task> Write a global regex that matches the token type, using word boundaries so it doesn't grab partial matches inside larger words. Explain the pattern and the boundary logic. Provide a snippet that extracts and deduplicates the tokens from my sample and prints them. Show the results. </task> <constraints> - Valid copy-paste syntax; correct word-boundary and Unicode handling for the flavor. - Avoid matching email @-signs when extracting mentions; explain how you prevent that. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the breakdown, then the snippet, then the deduplicated tokens from my sample. </format>
Produces a boundary-aware regex and snippet that extract hashtags, mentions, or ID tokens from text, ready to use.
Pro tip: Describe the exact token shape (letters-then-digits, prefix length); vague shapes make Claude over-match and pull in half the words in your text.
Search & Replace
5 promptsFind-and-Replace With Backreferences
11/30You are a regex engineer who writes precise find-and-replace transformations. <context> I need a search-and-replace regex (pattern plus replacement string) to transform text in bulk, using capture groups and backreferences. Deliver a ready-to-use pair with explanation and before/after examples. </context> <inputs> - Tool / flavor: [E.G. VS CODE, SED, JAVASCRIPT .replace, PYTHON re.sub] - What I have (before): [DESCRIBE OR PASTE SAMPLES] - What I want (after): [DESCRIBE THE TARGET FORMAT] - Apply globally / per line: [DESCRIBE] </inputs> <task> Write the SEARCH regex with capture groups and the REPLACEMENT string using backreferences ($1, \\1, or ${name} as the tool requires). Explain what each group captures and how the replacement reassembles it. Provide a before/after table with at least 6 examples, including one tricky case that should NOT be changed. </task> <constraints> - Use the correct backreference and flag syntax for the exact tool named. - Preserve any text that must stay untouched; explain how the pattern avoids collateral edits. - No destructive over-matching; keep replacements idempotent where possible. </constraints> <format> Return the search pattern and replacement string in a code block, then the group/replacement breakdown, then the before/after table. </format>
Delivers a search regex plus a backreference replacement string with a before/after table, ready to paste into your tool.
Pro tip: Name the exact tool (VS Code vs sed vs Python); backreference syntax is $1 in some and \1 in others, and getting it wrong just inserts literal text.
Reformat Dates, Names, or Case
12/30You are a regex engineer who reformats structured strings via substitution. <context> I need to reformat values in bulk (e.g. swap date format, reorder 'Last, First' to 'First Last', normalize casing). Deliver a ready-to-use search/replace pair with explanation and examples. </context> <inputs> - Transformation: [E.G. YYYY-MM-DD to MM/DD/YYYY, 'LAST, FIRST' to 'FIRST LAST', ETC.] - Tool / flavor: [E.G. VS CODE, SED, PYTHON re.sub, JAVASCRIPT] - Sample values: [PASTE 3-5] - Leave non-matching lines untouched: [YES / NO] </inputs> <task> Write the search regex (with capture groups) and the replacement template that performs the transformation. Explain how the groups map to the new order/format. Provide a before/after table for my samples plus one line that should NOT match, confirming it is left unchanged. </task> <constraints> - Correct group and backreference syntax for the named tool; handle optional whitespace around separators. - Case operations: use the tool's case modifiers if available (e.g. \\U, \\L in sed) or explain the alternative. - Idempotent: running it twice must not double-transform. </constraints> <format> Return the search and replacement in a code block, then the mapping breakdown, then the before/after table. </format>
Produces a substitution regex that reorders or reformats dates, names, or casing, with before/after proof, ready to use.
Pro tip: Ask Claude to confirm the transform is idempotent; a reorder regex run twice can quietly scramble already-fixed rows.
Bulk Rename Files or Variables
13/30You are a regex engineer who writes safe bulk-rename patterns. <context> I need to rename many things at once (files matching a pattern, or a variable/identifier across a codebase) using a regex search-and-replace. Deliver a ready-to-use pair with explanation and a dry-run preview. </context> <inputs> - Rename target: [FILENAMES / CODE IDENTIFIERS / STRINGS] - Tool: [E.G. VS CODE FIND-IN-FILES, SED, POWERSHELL, rename UTILITY] - Current pattern: [DESCRIBE OR SAMPLE] - Desired result: [DESCRIBE] - Case-sensitive: [YES / NO] </inputs> <task> Write the search regex and replacement for the named tool. Explain each capture group. Provide a dry-run preview table (Original -> New) for at least 6 realistic examples, and flag any names that would be caught unintentionally. Then give the exact command or steps to run it, including how to preview before applying. </task> <constraints> - Valid syntax for the exact tool; use word boundaries to avoid partial identifier matches. - Emphasize a dry run / preview first; warn about irreversible changes. - Avoid matching substrings inside unrelated names; explain the guard. </constraints> <format> Return the search/replacement, then the dry-run table, then the exact run command with a preview step, then a one-line safety caveat. </format>
Generates a boundary-safe rename regex plus the exact tool command and a dry-run preview, ready to use.
Pro tip: Always run the dry-run/preview Claude gives you first; a missing word boundary can rename half-matches deep inside unrelated names.
Strip or Insert Wrapping Markup
14/30You are a regex engineer who transforms text by adding or removing surrounding markup. <context> I need to wrap or unwrap text with markup or delimiters in bulk (e.g. wrap bare URLs in markdown links, strip HTML tags, add quotes around values, comment out lines). Deliver a ready-to-use search/replace pair with explanation and examples. </context> <inputs> - Operation: [WRAP / UNWRAP / STRIP] and what: [DESCRIBE] - Tool / flavor: [E.G. VS CODE, SED, JAVASCRIPT, PYTHON] - Sample lines: [PASTE 3-5] - Only affect lines matching: [OPTIONAL FILTER] </inputs> <task> Write the search regex and replacement that performs the wrap/unwrap/strip. Explain how the captured content is preserved while the surrounding markup is changed. Provide a before/after table for my samples, including a line that already has the target markup (must not double-wrap) and a line that should be skipped. </task> <constraints> - Correct syntax and flags for the named tool; non-greedy matching where stripping tags. - Must not double-wrap already-wrapped content; explain the guard (e.g. negative lookaround). - Preserve inner text exactly; no data loss. </constraints> <format> Return the search/replacement, then the breakdown, then the before/after table showing the no-double-wrap and skipped cases. </format>
Produces a wrap/unwrap/strip substitution regex that preserves inner text without double-wrapping, ready to use.
Pro tip: Ask for a guard against double-wrapping; without a negative lookaround, re-running the pattern nests markup inside markup.
Normalize Whitespace and Line Breaks
15/30You are a regex engineer who cleans up whitespace and line structure. <context> I have text with inconsistent whitespace (double spaces, trailing spaces, mixed tabs/spaces, blank-line runs, wrong line endings) and need regex to normalize it. Deliver ready-to-use search/replace pairs with explanation and examples. </context> <inputs> - Tool / flavor: [E.G. VS CODE, SED, PYTHON, JAVASCRIPT] - Fixes I want: [COLLAPSE MULTIPLE SPACES / TRIM TRAILING / TABS TO SPACES / COLLAPSE BLANK LINES / NORMALIZE CRLF] - Preserve indentation: [YES / NO] </inputs> <task> Provide one search/replace pair per requested fix (a small ordered recipe), each with the regex, the replacement, and a one-line explanation. Order them so they don't undo each other. Provide a before/after block showing a messy sample cleaned by running the recipe top to bottom. </task> <constraints> - Correct multiline/global flags for the named tool; be careful not to collapse intentional indentation if preservation is requested. - Each step must be idempotent and safe to re-run. - Explain the order dependency between steps. </constraints> <format> Return a numbered recipe (Step | Search | Replace | Why), then a before/after block demonstrating the full recipe on a messy sample. </format>
Delivers an ordered search/replace recipe that normalizes spaces, tabs, blank lines, and line endings, ready to run.
Pro tip: If indentation matters, tell Claude to preserve it; a blanket 'collapse multiple spaces' rule will happily flatten your code's indentation.
Log & Text Parsing
5 promptsParse Web Server Access Logs
16/30You are a regex engineer who parses server logs into structured fields. <context> I need a regex to parse access-log lines into named fields for analysis. Deliver a ready-to-use pattern with named groups, an explanation, and a parsing snippet. </context> <inputs> - Log format: [E.G. NGINX / APACHE COMBINED, OR PASTE 3-5 REAL LINES] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Fields I need: [E.G. ip, timestamp, method, path, status, bytes, referrer, user-agent] - Handle missing fields (dashes): [YES / NO] </inputs> <task> Write ONE regex with named capture groups matching the log format. Explain each group. Provide a snippet in the named language that reads lines, applies the regex, skips or flags non-matching lines, and prints each parsed record as a dict/object. Show the parsed output for my sample lines. </task> <constraints> - Named-group syntax correct for the flavor; handle quoted fields and '-' placeholders. - Robust to optional referrer/user-agent; explain how non-matching lines are handled. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then a Group | Meaning table, then the parsing snippet, then the parsed records from my sample lines. </format>
Produces a named-group regex and snippet that parse access-log lines into structured records, ready to use.
Pro tip: Paste 3-5 real log lines including an edge case (a 404, a bot user-agent); Claude hardens the pattern against the exact variants you actually get.
Extract Timestamps and Log Levels
17/30You are a regex engineer who filters and structures application logs. <context> I need to pull the timestamp and log level (and optionally the message) from application log lines, then filter to certain levels. Deliver a ready-to-use regex with explanation and a snippet. </context> <inputs> - Sample log lines: [PASTE 3-5] - Timestamp format: [DESCRIBE, E.G. ISO 8601, [YYYY-MM-DD HH:MM:SS]] - Levels to recognize: [E.G. DEBUG, INFO, WARN, ERROR, FATAL] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Filter to levels: [E.G. ERROR AND FATAL ONLY] </inputs> <task> Write a regex with named groups for timestamp, level, and message. Explain each group. Provide a snippet that parses lines, keeps only the requested levels, and prints the filtered structured results. Show the output for my sample lines. </task> <constraints> - Correct named-group and flag syntax for the flavor; tolerate optional brackets/whitespace around fields. - Level matching case-insensitive; explain how multi-line messages (stack traces) are handled or skipped. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the Group | Meaning table, then the filtering snippet, then the filtered records from my sample. </format>
Generates a regex and snippet that extract timestamps and log levels and filter to the levels you want, ready to use.
Pro tip: Tell Claude whether multi-line stack traces appear in your logs; otherwise the pattern parses the first line and drops the traceback.
Parse CSV or Delimited Lines Safely
18/30You are a regex engineer who splits delimited records, aware of quoting pitfalls. <context> I need to split delimited lines (CSV, TSV, pipe-separated) into fields with a regex, handling quoted fields that contain the delimiter. Deliver a ready-to-use pattern with explanation and a snippet, plus honest limits. </context> <inputs> - Delimiter: [COMMA / TAB / PIPE / OTHER] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Fields can be quoted: [YES / NO] - Quotes can contain the delimiter or escaped quotes: [DESCRIBE] - Sample lines: [PASTE 3-5] </inputs> <task> Write a regex that splits a single line into fields, correctly keeping quoted sections that contain the delimiter as one field. Explain the pattern. Provide a snippet that parses my sample lines into arrays. Then clearly state where regex CSV parsing breaks (embedded newlines, escaped quotes) and recommend a real CSV parser for full files. </task> <constraints> - Valid syntax for the flavor; handle empty fields and trailing delimiters. - Do NOT overpromise: be explicit that RFC 4180 edge cases (multiline quoted fields) need a proper parser. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the breakdown, then the snippet with parsed output for my samples, then a clear 'use a CSV library when...' caveat. </format>
Produces a quote-aware delimiter-splitting regex and snippet with honest limits on CSV edge cases, ready to use.
Pro tip: For real CSV files with multiline quoted cells, take Claude's caveat seriously and use a CSV library; regex handles single clean lines only.
Extract Stack Traces and Error Signatures
19/30You are a regex engineer who mines error signals out of noisy logs. <context> I need to detect and extract error blocks or stack-trace signatures from a log file so I can group and count them. Deliver a ready-to-use regex with explanation and a snippet. </context> <inputs> - Language/runtime of the traces: [E.G. JAVA, PYTHON, NODE, .NET] - Sample log with an error block: [PASTE A SNIPPET] - What to capture: [EXCEPTION TYPE / TOP FRAME / FULL BLOCK] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] </inputs> <task> Write a regex that identifies the start of an error/exception and captures the requested signature (e.g. exception class plus first frame). Explain the pattern. Provide a snippet that scans the log, extracts each error signature, and produces a count per unique signature. Show the grouped output for my sample. </task> <constraints> - Correct multiline/dotall handling for the flavor; capture across the relevant lines only. - Normalize signatures (strip line numbers/addresses) so the same error groups together; explain how. - Runnable snippet, no dependencies. </constraints> <format> Return the regex, then the breakdown, then the scan-and-count snippet, then a table of Signature | Count from my sample. </format>
Generates a regex and snippet that extract and group error/stack-trace signatures with counts, ready to use.
Pro tip: Ask Claude to strip line numbers and memory addresses from the signature; otherwise the 'same' error counts as dozens of unique ones.
Turn Freeform Notes Into Structured Records
20/30You are a regex engineer who converts semi-structured text into clean records. <context> I have semi-structured text (invoices, receipts, order confirmations, notes) and need regex to pull key fields into a structured record. Deliver a ready-to-use set of patterns with explanation and a snippet. </context> <inputs> - Sample text: [PASTE A REPRESENTATIVE BLOCK] - Fields to extract: [E.G. order number, date, total, customer, items] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Output shape: [JSON OBJECT / CSV ROW] </inputs> <task> Write one focused regex per field (labeled), each robust to small formatting differences. Explain each. Provide a snippet that runs all patterns over my sample and assembles a single structured record in the requested output shape. Show the assembled record for my sample, marking any field it could not find as null. </task> <constraints> - Valid syntax for the flavor; anchor to field labels where present to avoid false hits. - Tolerate optional whitespace, currency symbols, and label variations; explain the tolerance. - Runnable snippet; missing fields become null, never crash. </constraints> <format> Return a Field | Regex table, then a short breakdown of the tricky ones, then the assembly snippet, then the structured record from my sample. </format>
Produces per-field regexes and a snippet that assemble freeform text into a structured JSON or CSV record, ready to use.
Pro tip: Give Claude two or three samples with slightly different layouts; one-per-field regexes survive formatting drift far better than one giant pattern.
Data Cleaning
5 promptsRemove Unwanted Characters and Emojis
21/30You are a regex engineer who sanitizes messy text fields. <context> I need regex to strip unwanted characters from text (control chars, emojis, non-printable bytes, invisible unicode, HTML entities) while keeping the real content. Deliver a ready-to-use pattern with explanation and examples. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON] - Remove: [EMOJIS / CONTROL CHARS / NON-ASCII / ZERO-WIDTH CHARS / HTML ENTITIES] - Keep: [E.G. ACCENTED LETTERS, BASIC PUNCTUATION] - Sample dirty text: [PASTE A SNIPPET] </inputs> <task> Write the cleaning regex (or a short ordered set) plus the replacement (usually empty). Explain the character classes / unicode ranges used. Provide a snippet that cleans my sample and prints before/after. Confirm it preserves the characters I want to keep. </task> <constraints> - Correct unicode property/flag support for the flavor (e.g. the u flag, \\p{...} classes); explain any engine limitations. - Do not strip characters the user asked to keep; explain the guard. - Runnable snippet, no dependencies; idempotent. </constraints> <format> Return the regex(es), then the character-class breakdown, then the cleaning snippet, then a before/after of my sample. </format>
Produces a text-sanitizing regex that strips emojis, control chars, or invisible unicode while keeping real content, ready to use.
Pro tip: Spell out what to KEEP (accented letters, punctuation); a broad 'remove non-ASCII' rule silently deletes legitimate names and words.
Trim, Deduplicate, and Standardize Values
22/30You are a regex engineer who standardizes inconsistent data values. <context> I need regex to standardize a column of values (trim, collapse internal spacing, unify separators, fix casing, dedupe repeated tokens). Deliver a ready-to-use recipe with explanation and examples. </context> <inputs> - Tool / flavor: [E.G. PYTHON, JAVASCRIPT, SED] - Value type: [E.G. NAMES, TAGS, SKUS, ADDRESSES] - Rules: [TRIM / COLLAPSE SPACES / SEPARATOR TO X / TITLE-CASE / REMOVE DUP TOKENS] - Sample values: [PASTE 5-8] </inputs> <task> Provide an ordered search/replace recipe (one step per rule) that standardizes the values, each with regex, replacement, and a one-line reason. Explain the order. Provide a snippet that applies the whole recipe to my samples and prints before/after for each value. </task> <constraints> - Correct syntax/flags for the tool; each step idempotent and re-runnable. - Deduping repeated adjacent tokens via backreference; explain the pattern. - Preserve meaningful characters; no data loss. </constraints> <format> Return a numbered recipe (Step | Search | Replace | Why), then the runnable snippet, then a before/after table for my samples. </format>
Delivers an ordered regex recipe that trims, dedupes, and standardizes messy column values, with before/after proof, ready to use.
Pro tip: Ask for a backreference-based dedupe step; it's the clean way to collapse 'John John' or repeated tags that simple trimming misses.
Mask or Redact Sensitive Data (PII)
23/30You are a regex engineer who redacts sensitive data from text and logs. <context> I need regex to detect and mask PII (emails, phone numbers, credit cards, SSNs, API keys) in text before sharing or logging. Deliver ready-to-use patterns with explanation, a masking snippet, and clear limits. </context> <inputs> - Data types to mask: [EMAILS / PHONES / CREDIT CARDS / SSNS / API KEYS / OTHER] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Masking style: [FULL REPLACE WITH [REDACTED] / KEEP LAST 4 DIGITS / HASH] - Sample text: [PASTE A SNIPPET] </inputs> <task> Write one labeled regex per data type. Explain each. Provide a snippet that runs all patterns over my sample and replaces matches per the chosen masking style (e.g. keep last 4 of a card). Show before/after. Then state clearly that regex redaction is best-effort and can miss formats, so it must not be the only control for compliance. </task> <constraints> - Valid syntax for the flavor; minimize false positives on non-sensitive numbers (explain how). - Never log or echo the raw captured value; mask in place. - Be explicit about the limits and recommend a dedicated DLP/tokenization tool for compliance-grade needs. </constraints> <format> Return a Data type | Regex table, then the masking snippet, then a before/after of my sample, then a clear 'not sufficient for compliance alone' caveat. </format>
Produces per-type PII-detection regexes and a masking snippet (redact or keep-last-4) with honest limits, ready to use.
Pro tip: Treat regex redaction as a first pass, not a guarantee; heed Claude's caveat and layer a real DLP tool for anything compliance-bound.
Fix Encoding Artifacts and Smart Quotes
24/30You are a regex engineer who repairs text mangled by encoding issues. <context> I have text with encoding artifacts (mojibake like \u00e2\u20ac\u2122, smart quotes, non-breaking spaces, stray HTML entities). I need regex to clean it into plain, consistent text. Deliver a ready-to-use recipe with explanation and examples. </context> <inputs> - Tool / flavor: [E.G. PYTHON, JAVASCRIPT] - Artifacts present: [SMART QUOTES / EM-DASHES / NBSP / MOJIBAKE / HTML ENTITIES] - Target: [STRAIGHT ASCII / KEEP UNICODE BUT NORMALIZE] - Sample text: [PASTE A SNIPPET] </inputs> <task> Provide an ordered search/replace recipe mapping each artifact to its clean equivalent (e.g. curly quotes to straight, nbsp to space, common mojibake sequences to the right char). Explain each mapping. Provide a snippet that applies the recipe to my sample and prints before/after. Note where a proper decode/normalize step is the real fix versus a regex patch. </task> <constraints> - Correct unicode escapes and flags for the tool; be careful not to damage legitimate characters. - Idempotent recipe; safe to re-run. - Recommend fixing the source encoding when possible instead of only patching symptoms. </constraints> <format> Return a mapping table (Artifact | Replace with | Why), then the snippet, then a before/after of my sample, then a one-line 'fix the source encoding when you can' note. </format>
Delivers an ordered regex recipe that repairs smart quotes, nbsp, and mojibake into clean text, ready to use.
Pro tip: Regex patches the symptoms; if you control the pipeline, take Claude's advice and fix the decode step so artifacts never appear.
Validate and Split a Data File Column
25/30You are a regex engineer who validates and reshapes tabular data columns. <context> I have a column of values that should follow one format but has strays, and sometimes one field needs splitting into several. I need regex to (a) flag invalid rows and (b) split a combined field. Deliver ready-to-use patterns with explanation and a snippet. </context> <inputs> - Expected format of the column: [DESCRIBE OR SAMPLE] - Split task: [E.G. 'City, State ZIP' INTO THREE FIELDS - DESCRIBE] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT] - Sample values (mix of good and bad): [PASTE 6-10] </inputs> <task> Write a validation regex that matches only well-formed values, and a separate splitting regex with capture groups for the combined field. Explain both. Provide a snippet that flags each sample value as VALID/INVALID and, for valid ones, splits it into the target columns. Show a results table for my samples. </task> <constraints> - Valid syntax for the flavor; anchored validation, tolerant splitting where whitespace varies. - Clearly separate validation from extraction; explain why using two patterns is cleaner. - Runnable snippet; invalid rows are flagged, never silently dropped. </constraints> <format> Return the validation regex and the splitting regex, then breakdowns, then the snippet, then a table of Value | Valid? | Split fields for my samples. </format>
Produces a validation regex plus a splitting regex and a snippet that flag bad rows and split combined columns, ready to use.
Pro tip: Keep validation and splitting as two separate patterns; one over-clever regex that does both is where subtle data-loss bugs hide.
Most people use 10% of Claude. Tutorials unlock the rest.
AI Academy: 300+ hands-on tutorials on Claude, ChatGPT, Midjourney, and 50+ AI tools. New tutorials added every week.
Tricky Patterns & Lookarounds
5 promptsLookahead and Lookbehind Assertions
26/30You are a regex expert who teaches and applies lookaround assertions. <context> I need a regex that matches based on context without consuming it, using lookahead and/or lookbehind. Deliver a ready-to-use pattern with a clear explanation and examples. </context> <inputs> - What to match: [DESCRIBE, E.G. A NUMBER ONLY WHEN PRECEDED BY $ / A WORD NOT FOLLOWED BY ':'] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE, .NET] - Positive or negative context: [DESCRIBE THE CONDITION] - Sample text: [PASTE A SNIPPET] </inputs> <task> Write the regex using the appropriate positive/negative lookahead (?=...)(?!...) and/or lookbehind (?<=...)(?<!...). Explain exactly what each assertion checks and why the matched text excludes the context. Provide a test table with matches and non-matches from my sample, showing precisely which characters are captured. </task> <constraints> - Confirm the named flavor SUPPORTS lookbehind (JS, .NET, PCRE, modern Python do; some don't) and note fixed-width limitations if any. - Valid copy-paste syntax; be explicit about what is inside vs outside the match. - If lookbehind is unsupported, provide a capture-group workaround. </constraints> <format> Return the regex, then a breakdown of each assertion, then a match/non-match table highlighting the captured span, then a note on flavor support. </format>
Produces a lookaround-based regex that matches on context without consuming it, with a match-span test table, ready to use.
Pro tip: Always name your regex flavor here; lookbehind support and fixed-width rules vary by engine and a copied pattern can fail to even compile.
Match Balanced or Nested Delimiters
27/30You are a regex expert who handles delimiter matching and its limits. <context> I need to match content inside delimiters (parentheses, brackets, braces, quotes), possibly nested. Deliver a ready-to-use pattern with explanation, plus an honest verdict on whether regex can handle my nesting. </context> <inputs> - Delimiters: [E.G. ( ), [ ], { }, "..."] - Nesting depth: [NONE / ONE LEVEL / ARBITRARY] - Regex flavor / language: [E.G. PCRE, PYTHON regex MODULE, .NET, JAVASCRIPT] - Sample text: [PASTE A SNIPPET] </inputs> <task> If nesting is none or fixed, write a straightforward regex and explain it. If arbitrary nesting is required, state plainly that classic regex cannot match arbitrary nesting, then provide the recursive/balancing-group solution IF the named flavor supports it (PCRE (?R), .NET balancing groups, Python regex module) or recommend a parser otherwise. Provide a match table for my sample. </task> <constraints> - Be honest about the theoretical limit; do not fake a pattern that silently fails on deep nesting. - Use the correct recursion/balancing syntax for the exact flavor if applicable. - Valid, copy-paste syntax; explain the escape/greediness choices. </constraints> <format> Return the regex (or the parser recommendation), then the breakdown, then a match table for my sample, then a clear one-line verdict on regex feasibility for my nesting depth. </format>
Produces a delimiter-matching regex (or recursion/balancing solution) with an honest verdict on nesting feasibility, ready to use.
Pro tip: If you need arbitrary nesting, believe Claude when it says use a parser; a regex that 'mostly works' on nested delimiters fails on the inputs you least expect.
Non-Greedy and Backtracking-Safe Patterns
28/30You are a regex performance expert. <context> I have a regex that is either grabbing too much (greedy) or dangerously slow on some inputs (catastrophic backtracking). I need a corrected, efficient pattern with an explanation. Deliver a ready-to-use fix. </context> <inputs> - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE] - My current regex: [PASTE IT] - The problem: [MATCHES TOO MUCH / TIMES OUT / SLOW ON LONG INPUT] - Sample inputs (including a bad one): [PASTE] </inputs> <task> Diagnose why my pattern is greedy or backtracks catastrophically. Rewrite it using lazy quantifiers, atomic groups or possessive quantifiers (if the flavor supports them), or by restructuring to avoid nested/overlapping quantifiers. Explain the fix. Provide a before/after showing correct matches and note the performance improvement on the bad input. </task> <constraints> - Valid syntax for the flavor; only use atomic/possessive features the flavor actually supports (note JS lacks them and suggest alternatives). - Preserve the intended matches exactly while removing the pathology. - Explain the root cause (e.g. (a+)+ style overlap) in one or two sentences. </constraints> <format> Return the fixed regex, then a diagnosis of the original, then a before/after match table, then a one-line note on the performance gain. </format>
Diagnoses and rewrites a greedy or backtracking-prone regex into an efficient, correct pattern, ready to use.
Pro tip: Paste the exact input that hangs; catastrophic backtracking only shows on specific strings, and Claude needs that string to prove the fix.
Conditional and Alternation-Heavy Matching
29/30You are a regex expert who structures complex alternations cleanly. <context> I need one regex that matches several distinct-but-related formats (alternation), ideally capturing which variant matched. Deliver a ready-to-use pattern with explanation and examples. </context> <inputs> - The variants to match: [LIST EACH FORMAT WITH A SAMPLE] - Regex flavor / language: [E.G. PYTHON, JAVASCRIPT, PCRE] - Need to know which variant matched: [YES / NO] - Should any variant take priority: [DESCRIBE ORDER IF IT MATTERS] </inputs> <task> Write ONE regex using ordered alternation that matches all listed variants, with a named group per variant (or one shared structure) so I can tell which matched. Explain the ordering (why the most specific alternative comes first) and any shared prefix factoring. Provide a test table showing each variant sample and which branch matched. </task> <constraints> - Valid syntax for the flavor; correct alternation grouping and anchoring. - Order alternatives so a broad branch doesn't shadow a specific one; explain the ordering. - Keep it readable; if long, provide a verbose/commented version. </constraints> <format> Return the regex, then the branch breakdown, then a test table (Input | Matched variant), then a note on adding a new variant later. </format>
Produces an ordered-alternation regex that matches multiple formats and reports which variant matched, ready to use.
Pro tip: Tell Claude to put the most specific alternative first; alternation is ordered, so a broad branch listed early will shadow the precise ones.
Explain and Debug an Existing Regex
30/30You are a regex expert who reverse-engineers and hardens patterns. <context> Someone handed me a regex I don't fully understand (or that misbehaves) and I need a plain-English explanation plus a corrected version. Deliver a full breakdown and a fixed pattern. </context> <inputs> - The regex: [PASTE IT] - Regex flavor / language: [E.G. JAVASCRIPT, PYTHON, PCRE] - What it's supposed to do: [DESCRIBE] - Inputs where it fails or surprises me: [PASTE EXAMPLES] </inputs> <task> Explain the regex token by token in plain English. Identify what it actually matches versus the intended behavior, and pinpoint the bug on my failing inputs. Provide a corrected version, explain the change, and give a test table with matches and non-matches (including my failing inputs now passing). </task> <constraints> - Accurate to the exact flavor's semantics (flags, escaping, group types). - Distinguish clearly between what the ORIGINAL does and what the FIX does. - Valid, copy-paste-ready corrected pattern; note any required flags. </constraints> <format> Return a token-by-token table (Token | Meaning), then the diagnosis, then the fixed regex, then a before/after test table including my failing inputs. </format>
Delivers a token-by-token explanation of an existing regex plus a debugged, corrected version with a test table, ready to use.
Pro tip: Include the inputs where it currently misbehaves; Claude anchors the fix to real failures instead of guessing at what 'correct' means.
Frequently Asked Questions
Prompts are the starting line. Tutorials are the finish.
A growing library of 300+ hands-on tutorials on ChatGPT, Claude, Midjourney, and 50+ AI tools. New tutorials added every week.
7-day free trial. Cancel anytime.