Regex replace
Replace every match of a regular expression, with backreferences such as \1 in the replacement.
Input
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
| Name | Type | Required | What 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.
Related tools
- Regex testerTest a regular expression against text and see every match with its position and groups.
regex-test - Find and replaceReplace every occurrence of a word or phrase in text, exactly as typed, with a count of the changes.
find-replace - Regex extractorPull every match of a regular expression out of text as a simple list, or just one capture group.
regex-extract - Apply a patchApply a unified diff to a text and get the patched result, with clear errors when a hunk does not fit.
patch-apply - Case converterConvert text between lower, UPPER, Title, Sentence, camelCase, PascalCase, snake_case, kebab-case and more.
case-convert - Escape and unescape textEscape or unescape text for HTML, URLs, JSON strings, shell commands, regular expressions and CSV fields.
escape-unescape