# x402 Utils – Regex Match & Replace (RE2)

> x402 Utils – Regex Match & Replace (RE2) is a paid API for AI agents from utils.kagurazaka.dev, paid per call via x402, $0.001/call, status unknown (last checked 2026-10-29).

Run an RE2 regular expression on text, returning all matches with positions and capture groups, plus an optional replacement applied to the text.

## Facts

- Endpoint: POST https://utils.kagurazaka.dev/v1/regex?utm_source=zero.xyz
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-29
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-utils-regex-match-replace-re2-3bd25ca4
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_t7w-X94dF-2dlArv_M10m

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 x402-utils-regex-match-replace-re2-3bd25ca4 -d '<json body>'
```

Example prompt: 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.'

## When to prefer this

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).

## Known failure modes

- 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

## How this service works

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).

## Output

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).

## Request schema (JSON Schema)

```json
{
 "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"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "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"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/x402-utils-regex-match-replace-re2-3bd25ca4/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from utils.kagurazaka.dev](https://www.zero.xyz/host/utils.kagurazaka.dev/llms.txt)
