Regex replace

Replace every match of a regular expression, with backreferences such as \1 in the replacement.

Input

The regular expression (Python syntax).
The text to change.
Replacement text. \1 or \g<name> inserts a group, \g<0> the whole match.
Letters that switch options on: i (ignore case), m (^ and $ match at each line), s (dot matches line breaks), x (allow spaces and comments).
Replace at most this many matches. 0 replaces all.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/regex-replace \
  -H 'Content-Type: application/json' \
  -d '{"input":{"pattern":"(\\w+)@(\\w+)\\.com","text":"[email protected]","replacement":"\\2: \\1"}}'
import json, urllib.request

body = {'input': {'pattern': '(\\w+)@(\\w+)\\.com', 'text': '[email protected]', 'replacement': '\\2: \\1'}}
request = urllib.request.Request("https://setget.net/v1/tools/regex-replace", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/regex-replace", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"pattern":"(\\w+)@(\\w+)\\.com","text":"[email protected]","replacement":"\\2: \\1"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "regex-replace",
  "input": {
    "pattern": "(\\w+)@(\\w+)\\.com",
    "text": "[email protected]",
    "replacement": "\\2: \\1"
  }
}
{
  "input": {
    "pattern": "(\\w+)@(\\w+)\\.com",
    "text": "[email protected]",
    "replacement": "\\2: \\1"
  }
}

Endpoint: POST /v1/tools/regex-replace. Over MCP: run_tool with slug: "regex-replace". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
pattern string yes The regular expression (Python syntax).
text string yes The text to change.
replacement string no Replacement text. \1 or \g<name> inserts a group, \g<0> the whole match. Default: "".
flags string no Letters that switch options on: i (ignore case), m (^ and $ match at each line), s (dot matches line breaks), x (allow spaces and comments). Default: "".
count integer no Replace at most this many matches. 0 replaces all. Default: 0.

Examples

Input
{
  "pattern": "(\\w+)@(\\w+)\\.com",
  "text": "[email protected]",
  "replacement": "\\2: \\1"
}
Result
{
  "text": "example: sam",
  "replacements": 1
}

Collapse whitespace

Input
{
  "pattern": "\\s+",
  "text": "a   b \n c",
  "replacement": " "
}
Result
{
  "text": "a b c",
  "replacements": 2
}

Questions

Which regex syntax is this?
Python's. It is close to PCRE and JavaScript, with named groups written (?P<name>...).
Can I write $1 for a group?
No. Use \1, or \g<1> when a digit follows, and \g<name> for named groups. A dollar sign is inserted as it is.
How do I insert a real backslash?
Write two backslashes in the replacement.