{"uid":"cap_t7w-X94dF-2dlArv_M10m","slug":"x402-utils-regex-match-replace-re2-3bd25ca4","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://utils.kagurazaka.dev/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_oetx5BszZxDNFVcs3DuU5","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":"Run an RE2 regular expression on text, returning all matches with positions and capture groups, plus an optional replacement applied to the text.","exampleAgentPrompt":"Find all ISO dates in this text using the pattern `(\\d{4})-(\\d{2})-(\\d{2})` with named group `year` for the first segment, and replace each match with `$2/$3/$1`: 'Invoice date: 2026-03-15, due: 2026-04-01.'","exampleUseCases":[{"title":"Extract dates from invoice text","prompt":"Pull every date out of this invoice text using the pattern `(?P<year>\\d{4})-(\\d{2})-(\\d{2})` and also give me the text with each date rewritten in MM/DD/YYYY format using `$2/$3/$1`: 'Issued: 2026-01-10, due: 2026-02-10, paid: 2026-02-09.'"},{"title":"Find all emails in a document","prompt":"Scan this block of text for email addresses using the regex `[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}` and list every match with its position: 'Contact alice@example.com or support@company.org for help.'"},{"title":"Case-insensitive keyword redaction","prompt":"Replace every occurrence of the word 'confidential' (case-insensitive) with '[REDACTED]' in this text using the pattern `confidential` with the `i` flag: 'This CONFIDENTIAL report and all confidential attachments must not be shared.'"}],"resultDescription":"A JSON object with: `matched` (boolean), `count` (number of matches), `matches` (array of objects each with `index`, `match`, `groups` array, and `named` map of named capture groups), and `replaced` (the input text with the replacement pattern 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 is rejected","Pattern exceeding 2000 characters is rejected","Invalid flag characters return an error","Missing required fields (text or pattern) return a validation error","Payment not included or insufficient USDC results in HTTP 402"],"whenToPreferThis":"Choose this endpoint when you need reliable, linear-time regex matching on arbitrary text — especially when you want match positions, capture groups (including named groups), and optional in-place replacement in a single call. Prefer it over client-side regex when running in an environment without a regex engine, or when you need RE2 safety guarantees (no catastrophic backtracking). Not suitable if you need lookahead, lookbehind, or backreferences (use a PCRE-based service instead).","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T12:36:53.729Z","isFirstParty":false,"canonicalSlug":"x402-utils-regex-match-replace-re2-3bd25ca4"}