{"uid":"cap_0De3GfG4eUqstIUXdLHqb","slug":"x402-utils-regex-match-replace-re2-3c533193","name":"x402 Utils – Regex Match & Replace (RE2)","description":"Run a regular expression on a text: every match with its position and capture groups (named too), and the text with a replacement applied. RE2 syntax, which runs in linear time (no lookaround or backreferences).","url":"https://qcb7fnxsbd7fbhj4.68r.lambda-web.us-east-1.on.aws/v1/regex?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"text":{"type":"string","description":"the text (up to 1 MB)"},"flags":{"type":"string","description":"any of i (ignore case), m (multiline), s (dot matches newline)"},"pattern":{"type":"string","description":"the pattern (up to 2000 characters)"},"replacement":{"type":"string","description":"optional replacement, $1 for groups"}}},"responseSchema":{"type":"json","example":{"count":2,"matched":true,"matches":[{"index":5,"match":"2026-10","named":{"year":"2026"},"groups":["2026","10"]}],"replaced":"from 10/2026 to 01/2027"}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_Rs4hhKgJsvluzPklPw4VP","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Runs a RE2 regular expression on a text, returning all matches with positions and capture groups, plus an optional replacement result.","exampleAgentPrompt":"Find all dates in ISO format (like 2026-10-15) in this text using the pattern `(\\d{4})-(\\d{2})-(\\d{2})` and replace them with the format DD/MM/YYYY using `$3/$2/$1`: 'Meeting on 2026-10-15 and follow-up on 2027-01-03.'","exampleUseCases":[{"title":"Extract all email addresses from text","prompt":"Pull out every email address from this paragraph using a regex — pattern `[\\w.+-]+@[\\w-]+\\.[\\w.]+` — and tell me how many there are and where each one appears: 'Contact alice@example.com or support@company.org for help.'"},{"title":"Find and reformat dates in a document","prompt":"I have this text: 'Invoice date: 2025-07-14, due: 2025-08-01.' Use the pattern `(\\d{4})-(\\d{2})-(\\d{2})` with named groups year, month, day and replace each date with the format $3/$2/$1 so it reads European style."},{"title":"Validate log lines with capture groups","prompt":"Check if any lines in this server log match the pattern `^ERROR (\\d{3}): (.+)$` with multiline mode on, and give me the status code and message from each match: 'INFO 200: OK\\nERROR 503: Service Unavailable\\nERROR 404: Not Found'"}],"resultDescription":"Returns a JSON object with: `matched` (boolean), `count` (number of matches), `matches` array (each with `index`, `match` string, `groups` array of positional captures, `named` map of named captures), and `replaced` (the full text with the replacement applied, if a replacement was provided).","failureModes":["Invalid RE2 pattern syntax returns an error — RE2 does not support lookahead, lookbehind, or backreferences","Text exceeding 1 MB will be rejected","Pattern exceeding 2000 characters will be rejected","Invalid flag characters (anything other than i, m, s) will cause an error","Payment failure or missing x402 payment header returns 402 status"],"whenToPreferThis":"Choose this endpoint when you need server-side, guaranteed linear-time regex execution (RE2) without risk of catastrophic backtracking, when you need both match extraction (positions + groups) and replacement in a single call, or when your runtime doesn't have a regex engine available. Prefer over client-side solutions when working with untrusted patterns that could cause ReDoS vulnerabilities, or when you need named capture groups and positional indices reliably returned as structured JSON.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T12:35:50.890Z","isFirstParty":false,"canonicalSlug":"x402-utils-regex-match-replace-re2-3c533193"}