API documentation
The regex101 API exposes a live OpenAPI 3.1 contract and an interactive Swagger UI at regex101.com/api/docs. The contract is generated from the deployed API, so use it as the reference for the paths, fields, and responses that it documents.
The examples below demonstrate two common workspace operations. They do not replace the complete API reference.
For AI clients, use the regex101 MCP server instead of calling these routes directly.
Authentication
The website uses a secure session cookie. Compatible MCP clients use the browser OAuth flow and store the same session credential as a bearer token. See MCP server for connection instructions.
Direct API requests can use the same token. Send it in the Authorization header. A bearer request
does not need a Cookie header.
Treat the token like a password. Store it outside source control, use it only over HTTPS, and do not include it in URLs or logs:
Authorization: Bearer <token>
The authenticated examples use REGEX101_TOKEN so that the token does not appear in source code.
Get a workspace
Use the workspace permalink fragment and version from a regex101 URL. Authentication is optional
for public workspaces and required when the requested workspace is private. These examples request
a public workspace without an Authorization header.
- cURL
- Node.js
- Python
curl --fail-with-body \
"https://regex101.com/api/workspace/$WORKSPACE_ID/$WORKSPACE_VERSION"
const workspaceId = process.env.WORKSPACE_ID;
const workspaceVersion = process.env.WORKSPACE_VERSION;
const response = await fetch(
`https://regex101.com/api/workspace/${workspaceId}/${workspaceVersion}`
);
if (!response.ok) {
throw new Error(`regex101 returned ${response.status}: ${await response.text()}`);
}
console.log(await response.json());
import os
import requests
workspace_id = os.environ["WORKSPACE_ID"]
workspace_version = os.environ["WORKSPACE_VERSION"]
response = requests.get(
f"https://regex101.com/api/workspace/{workspace_id}/{workspace_version}",
timeout=30,
)
response.raise_for_status()
print(response.json())
An abridged response looks like this:
{
"permalinkFragment": "AbC123",
"version": 1,
"preferredEditorMode": "match",
"regex": "regex\\d+",
"testStrings": [
{
"name": null,
"value": "regex101",
"disabled": false
}
],
"flags": "g",
"delimiter": "/",
"flavor": "pcre2",
"isPrivate": false,
"isEditable": true,
"isOwner": false
}
The full response also contains editor data, permissions, tags, unit tests, and substitution data.
Save a workspace
POST /api/workspace creates a workspace. Add permalinkFragment to the request body to save a
new version of an existing workspace.
The examples below require REGEX101_TOKEN, so the new workspace belongs to the signed-in account.
To create an anonymous workspace, omit the Authorization header. Anonymous workspaces are
controlled through the delete codes returned by the API.
- cURL
- Node.js
- Python
curl --fail-with-body \
--request POST \
--header "Authorization: Bearer $REGEX101_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"regex": "regex\\d+",
"testStrings": [
{
"name": null,
"value": "Try regex101 and regex42",
"disabled": false
}
],
"substitution": null,
"listSubstitution": null,
"unitTests": [],
"flags": "g",
"delimiter": "/",
"flavor": "pcre2"
}' \
"https://regex101.com/api/workspace"
const token = process.env.REGEX101_TOKEN;
const response = await fetch('https://regex101.com/api/workspace', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
regex: 'regex\\d+',
testStrings: [
{
name: null,
value: 'Try regex101 and regex42',
disabled: false,
},
],
substitution: null,
listSubstitution: null,
unitTests: [],
flags: 'g',
delimiter: '/',
flavor: 'pcre2',
}),
});
if (!response.ok) {
throw new Error(`regex101 returned ${response.status}: ${await response.text()}`);
}
console.log(await response.json());
import os
import requests
token = os.environ["REGEX101_TOKEN"]
response = requests.post(
"https://regex101.com/api/workspace",
headers={"Authorization": f"Bearer {token}"},
json={
"regex": r"regex\d+",
"testStrings": [
{
"name": None,
"value": "Try regex101 and regex42",
"disabled": False,
}
],
"substitution": None,
"listSubstitution": None,
"unitTests": [],
"flags": "g",
"delimiter": "/",
"flavor": "pcre2",
},
timeout=30,
)
response.raise_for_status()
print(response.json())
A new workspace returns HTTP 201 with its permalink and delete codes:
{
"permalinkFragment": "AbC123",
"permalinkVersionDeleteCode": "<version-delete-code>",
"permalinkDeleteCode": "<workspace-delete-code>",
"versionDeleteCode": "<version-delete-code>",
"regexDeleteCode": "<workspace-delete-code>",
"version": 1,
"isLibraryEntry": false
}
The versionDeleteCode and regexDeleteCode fields are deprecated compatibility aliases. Use
permalinkVersionDeleteCode and permalinkDeleteCode in new integrations.