---
title: "Match, replace or split with a regular expression"
method: POST
path: "/regex-test.php"
tags: ["text"]
---

# Match, replace or split with a regular expression

`POST /regex-test.php`

## Request

- Base URL: `https://mate.tools/api/v1`
- URL: `https://mate.tools/api/v1/regex-test.php`
- Auth: none declared

Tests a PCRE pattern against text. `operation=match` returns the first match; `match_all` returns all matches with offsets and capture groups; `replace` performs substitution; `split` divides the text on matches. ReDoS-protected: catastrophic patterns return 422 `pcre_error: backtrack limit exhausted`.

## Request body

- object
  - `pattern` string, required
  - `text` string, required
  - `flags` string: any of i, m, s, u, x
  - `operation` 'match' | 'match_all' | 'replace' | 'split'
  - `replacement` string
  - `split_limit` integer

## Response `200`

Success

## Other responses

- `400`: Malformed request
- `413`: Request body or text exceeds 1 MB
- `422`: PCRE failure (catastrophic pattern, JIT limit, etc.)
- `429`: Rate limit exceeded (60/min, 600/hour per IP). Includes Retry-After header.

---

[API](https://skmtc.dev/mate/apis/mate-tools-api.md) · [All operations](https://skmtc.dev/mate/apis/mate-tools-api/llms.txt) · [OpenAPI document](https://skmtc.dev/mate/apis/mate-tools-api/revisions/874670b78962?raw)
