Skip to content
POST AI agent ready /v1/regex/replace

Regex Replace API - Free Find & Replace

Applies a regex pattern to a string and replaces all matches with the specified replacement. Supports backreferences ($1, $2) for capture groups in the replacement string.

Parameters

stringrequired

The regular expression pattern to match.

string

Regex flags (e.g., "g" for global replacement).

stringrequired

The input string to perform replacement on.

stringrequired

The replacement string. Use $1, $2 for capture group backreferences.

Code examples

curl -X POST https://api.botoi.com/v1/regex/replace \
  -H "Content-Type: application/json" \
  -d '{"pattern":"(\\d{4})-(\\d{2})-(\\d{2})","flags":"g","testString":"Event date: 2026-03-26","replacement":"$2/$3/$1"}'

When to use this API

Reformat dates across a document

Convert all ISO dates (YYYY-MM-DD) to US format (MM/DD/YYYY) or any other format using capture group backreferences.

Redact sensitive information in logs

Replace credit card numbers, SSNs, or API keys in log files with masked values like "****" before sharing.

Frequently asked questions

How do backreferences work in the replacement string?
Use $1 for the first capture group, $2 for the second, and so on. $0 refers to the entire match.
Does the replacement happen only once or globally?
It depends on whether you include the "g" flag. Without "g", only the first match is replaced. With "g", all matches are replaced.
Can I use lookahead and lookbehind in the pattern?
Yes. The regex engine supports lookahead (?=), negative lookahead (?!), lookbehind (?<=), and negative lookbehind (?<!).
Is there a ReDoS protection for replacement patterns?
Yes. The same 5-second execution timeout applies. Patterns that cause catastrophic backtracking are terminated.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.