Regex replace
Try it interactively →POST /api/regex-replaceFind-and-replace text with a JavaScript-style regex. Supports capture groups in the replacement (`$1`, `$2`, …), the `g`/`i`/`m`/`s`/`u` flags, and a count cap.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| pattern* | string | — | Regex pattern (without slashes). |
| replacement* | string | — | Replacement string. Supports `$&`, `$1`, `$<name>`, `$$`. |
| text* | string | — | Text to operate on. |
| flags | string | "" | Regex flags (e.g. `i`, `im`, `iu`). `g` is added unless `firstOnly` is true. |
| firstOnly | boolean | false | Replace only the first match instead of all. |
Response
Modes: json, text. Cache: yes (24h TTL).
Code samples
Built from the phone example.
curl -X POST https://api.xtract.bot/api/regex-replace \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
-H "X-Api-Key: $XTRACT_API_KEY" \
-d '{
"pattern": "(\\d{3})(\\d{3})(\\d{4})",
"replacement": "$1-$2-$3",
"text": "Call 0212345678 or 0398765432 today.",
"flags": "g"
}'