# Regex Replace (RE2)

> Regex Replace (RE2) is a paid API for AI agents from regex.openverbs.com, paid per call via x402, $0.004/call, status unknown (last checked 2026-09-14).

Replaces all or first occurrences of a RE2 regex pattern in a string with a replacement that may reference capture groups.

## Facts

- Endpoint: POST https://regex.openverbs.com/v1/replace
- Price: $0.004/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/regex-replace-re2-1af9f3ac
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_Ce1tPyb_v0g9O8vnyGv6f

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability regex-replace-re2-1af9f3ac -d '<json body>'
```

Example prompt: In this text — 'Hello World, hello world' — replace every occurrence of 'hello' (case-insensitive) with 'Hi' using RE2 regex, replacing all matches.

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

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.

## Output

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.

## Request schema (JSON Schema)

```json
{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "type": "object",
 "properties": {
  "input": {
   "type": "object",
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "type": "string",
     "enum": [
      "POST"
     ]
    },
    "bodyType": {
     "type": "string",
     "enum": [
      "json",
      "form-data",
      "text"
     ]
    },
    "body": {
     "type": "object",
     "properties": {
      "pattern": {
       "type": "string",
       "minLength": 1,
       "maxLength": 4096,
       "description": "RE2 regular-expression pattern."
      },
      "input": {
       "type": "string",
       "maxLength": 1000000,
       "description": "The subject text."
      },
      "replacement": {
       "type": "string",
       "maxLength": 1000000,
       "description": "Replacement text; supports $1/${name} group references."
      },
      "flags": {
       "type": "string",
       "maxLength": 8,
       "description": "Any of i (case-insensitive), m (multiline ^$), s (dotall). Default none."
      },
      "all": {
       "type": "boolean",
       "description": "Replace every match. Default true."
      }
     },
     "required": [
      "pattern",
      "input",
      "replacement"
     ],
     "additionalProperties": false
    }
   },
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "additionalProperties": false
  }
 },
 "required": [
  "input"
 ]
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/regex-replace-re2-1af9f3ac/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from regex.openverbs.com](https://www.zero.xyz/host/regex.openverbs.com/llms.txt)
