{"uid":"cap_Ce1tPyb_v0g9O8vnyGv6f","slug":"regex-replace-re2-1af9f3ac","name":"Regex Replace (RE2)","description":"Replace matches of a RE2 pattern with a replacement string. Replaces all matches by default (set all=false for first-only). The replacement may reference capture groups with $1, $2 or ${name}. Returns the resulting string.","url":"https://regex.openverbs.com/v1/replace","method":"POST","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method","bodyType","body"],"properties":{"body":{"type":"object","required":["pattern","input","replacement"],"properties":{"all":{"type":"boolean","description":"Replace every match. Default true."},"flags":{"type":"string","maxLength":8,"description":"Any of i (case-insensitive), m (multiline ^$), s (dotall). Default none."},"input":{"type":"string","maxLength":1000000,"description":"The subject text."},"pattern":{"type":"string","maxLength":4096,"minLength":1,"description":"RE2 regular-expression pattern."},"replacement":{"type":"string","maxLength":1000000,"description":"Replacement text; supports $1/${name} group references."}},"additionalProperties":false},"type":{"type":"string","const":"http"},"method":{"enum":["POST"],"type":"string"},"bodyType":{"enum":["json","form-data","text"],"type":"string"}},"additionalProperties":false}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.004","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.004/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_l0zs8B90GBzUlgBfVYFN-","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.004","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Replaces all or first occurrences of a RE2 regex pattern in a string with a replacement that may reference capture groups.","exampleAgentPrompt":"In this text — 'Hello World, hello world' — replace every occurrence of 'hello' (case-insensitive) with 'Hi' using RE2 regex, replacing all matches.","exampleUseCases":[{"title":"Redact PII from log lines","prompt":"Take this server log text and replace every email address matching the pattern '[\\w.+-]+@[\\w-]+\\.[\\w.]+' with '[REDACTED]', replacing all matches."},{"title":"Reformat dates in a document","prompt":"I have a long document where dates are written as MM/DD/YYYY — can you replace them all with YYYY-MM-DD format using a regex capture group substitution? The pattern would be '(\\d{2})/(\\d{2})/(\\d{4})' and replacement '$3-$1-$2'."},{"title":"Normalize whitespace in user input","prompt":"Clean up this user-submitted text by replacing all runs of two or more whitespace characters with a single space, replacing every match."}],"resultDescription":"Returns a JSON object containing the resulting string after all specified regex replacements have been applied. The output reflects the modified text with every matched occurrence (or just the first, if all=false) substituted with the replacement string, which may include capture group back-references.","failureModes":["Invalid RE2 pattern syntax returns an error (RE2 does not support lookaheads, backreferences, etc.)","Input text exceeding 1,000,000 characters is rejected","Pattern string exceeding 4,096 characters is rejected","Invalid flag characters in flags field cause an error","Payment failure or insufficient balance returns 402"],"whenToPreferThis":"Use this endpoint when you need deterministic, linear-time regex replacement guaranteed by the RE2 engine (safe against ReDoS). Prefer it over client-side regex when running in a sandboxed or serverless environment without regex libraries, or when you need a simple API-callable string transform without spinning up compute. The RE2 constraint means avoid it if you need PCRE features like lookaheads or backreferences in the pattern itself.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-14T18:41:21.273Z","isFirstParty":false}