-
-
Notifications
You must be signed in to change notification settings - Fork 199
API
#Regex101.com API Methods
There are a number of methods available to you via the API. Some methods require you to authenticate first. Authentication can be initiated via a call to https://regex101.com/connect/[provider]
, where /[provider]
can be /github
, /google
, or /twitter
.
The oauth mechanism itself is beyond the purpose of API documentation.
#Table of Contents
- Table of Contents
- ✦ Public Methods
- ✦ Authenticated methods
- Limitations
- Contact
#✦ Public Methods
##✪ Retrieve an Entry ⇧
URL | Method |
---|---|
/api/regex/uniqueID/revision | GET |
###Required URL parts:
- uniqueID: entry's unique ID
- revision: entry's revision number
###Sample call:
####cURL
curl -X GET "https://regex101.com/api/regex/AaKDTO/1"
See this sample call in other languages
####PHP ```php $curl = curl_init();
curl_setopt_array($curl, array( CURLOPT_URL => "https://regex101.com/api/regex/AaKDTO/1", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", ));
$response = curl_exec($curl); $err = curl_error($curl);
curl_close($curl);
if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
####JavaScript
```javascript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/regex/AaKDTO/1");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/regex/AaKDTO/1",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/regex/AaKDTO/1"
response = requests.request("GET", url)
print(response.text)
###Success Response: 200
{
"regex": "testing \\w+",
"testString": "testing retrieval",
"flags": "gs",
"delimiter": "/",
"flavor": "pcre",
"substitution": null,
"title": null,
"unitTests": [
{
"description": "testing ok festering not ok",
"criteria": "DOES_NOT_MATCH",
"target": "REGEX",
"testString": "festering",
"compareString": null
}
],
"isFavorite": false,
"isLibraryEntry": false
}
###Error response: 404
{"error":"Regex does not exist (/r/AaKDTO/1) (Error Id: 5b30f207-a459-40b4-812a-f7213b2efee5)"}
##✪ Delete an Entry ⇧
URL | Method |
---|---|
/api/regex | DELETE |
###Required Parameters:
- deleteCode: entry's specific delete code
###Sample call: ####cURL
curl \
-X DELETE \
-H "Content-Type: application/json" \
-d@- \
"https://regex101.com/api/regex" <<EOF
{
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR"
}
EOF
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/regex",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_POSTFIELDS => "{\"deleteCode\":\"00f0lICHYn0J0Q000TVxXKdR\"}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("DELETE", "https://regex101.com/api/regex");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "DELETE",
"hostname": "regex101.com",
"port": null,
"path": "/api/regex",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ deleteCode: '00f0lICHYn0J0Q000TVxXKdR' }));
req.end();
####Python
import requests
url = "https://regex101.com/api/regex"
payload = "{\"deleteCode\":\"00f0lICHYn0J0Q000TVxXKdR\"}"
headers = {'content-type': 'application/json'}
response = requests.request("DELETE", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"message": "Your regex has been deleted."
}
###Error Response 404
{"error": "Invalid delete code (Error Id: de5d83ef-fe6c-4127-83d8-4d5c9abdfc5a)"}
##✪ Create an Entry [⇧](#table-of-contents)
URL | Method | content-type |
---|---|---|
/api/regex | POST | application/json |
###Required Parameters:
- regex: your regular expression
- flags: flags to be enabled for this regular expression
-
delimiter: delimiter character to be used, i.e.
"
, or@
, or/
-
flavor: desired regular expression engine, i.e.
pcre
, orpython
, orjavascript
, etc.
flavor | delimiter choice |
---|---|
pcre(php) |
/ or ~ or @ ; or % or `
|
javascript | / |
python |
" or '
|
golang | ` |
###Optional Parameters:
- testString: desired test string
- substitution: a substitution pattern for this regex
-
unitTests: JSON array containing each unit test, composed of the following variables:
- description: a description for this unit test
- testString: string to test against using entry's regular expression
- compareString: string to compare resulting match to
-
target: can either be
REGEX
for the entry regex or0
for the entry's resulting match -
criteria: match condition, depending on target; it can be
DOES_MATCH
,DOES_NOT_MATCH
,STARTS_WITH
,ENDS_WITH
,CONTAINS
,EQUALS
orIS_NULL
criteria | explanation | applicable target |
---|---|---|
DOES_MATCH |
assert that the regex matches testString of unit test | REGEX |
DOES_NOT_MATCH |
assert that the regex does not match testString of unit test | REGEX |
STARTS_WITH |
assert that the regex match or selected capture group, given testString of unit test, starts with compareString |
0 or capture group #
|
ENDS_WITH |
assert that the regex match or selected capture group, given testString of unit test, ends with compareString |
0 or capture group #
|
CONTAINS |
assert that the regex match or selected capture group, given testString of unit test, contains compareString |
0 or capture group #
|
EQUALS |
assert that the regex match or selected capture group, given testString of unit test, equals compareString |
0 or capture group #
|
IS_NULL |
assert that the full match or selected capture group, given testString of unit test, does not match or capture anything |
0 or capture group #
|
###Sample call: ####cURL
curl -X POST -H "Expect:" -H "Content-Type: application/json" -d ' {
"regex":"\\w+",
"testString":"bird is the word",
"flags":"g",
"delimiter":"@",
"flavor":"pcre",
"unitTests":[
{ "description":"testing ok festering not ok",
"criteria":"DOES_NOT_MATCH",
"target":"REGEX",
"testString":"festering" },
{ "description":"word should match",
"criteria":"DOES_MATCH",
"testString":"awesomelicious",
"target":"REGEX" },
{ "description":"match starts with",
"criteria":"STARTS_WITH",
"testString":"bird",
"target":"0",
"compareString":"bird" },
{ "description":"match ends with",
"criteria":"ENDS_WITH",
"testString":"poop",
"target":"0",
"compareString":"poop" },
{ "description":"there should be a word in here somewhere",
"criteria":"CONTAINS",
"testString":"word",
"target":"0",
"compareString":"word" },
{ "description":"bird is the word, for real",
"criteria":"EQUALS",
"testString":"bird is the word",
"target":"0",
"compareString":"bird is the word" },
{ "description":"no result",
"criteria":"IS_NULL",
"testString":"fishing",
"target":"0",
"compareString":null }
]
}' "https://regex101.com/api/regex"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
$fields = array (
'regex' => '\w+',
'testString' => 'bird is the word',
'flags' => 'g',
'delimiter' => '@',
'flavor' => 'pcre',
'unitTests' =>
array (
0 =>
array (
'description' => 'testing ok festering not ok',
'criteria' => 'DOES_NOT_MATCH',
'target' => 'REGEX',
'testString' => 'festering',
),
1 =>
array (
'description' => 'word should match',
'criteria' => 'DOES_MATCH',
'testString' => 'awesomelicious',
'target' => 'REGEX',
),
2 =>
array (
'description' => 'match starts with',
'criteria' => 'STARTS_WITH',
'testString' => 'bird',
'target' => '0',
'compareString' => 'bird',
),
3 =>
array (
'description' => 'match ends with',
'criteria' => 'ENDS_WITH',
'testString' => 'poop',
'target' => '0',
'compareString' => 'poop',
),
4 =>
array (
'description' => 'there should be a word in here somewhere',
'criteria' => 'CONTAINS',
'testString' => 'word',
'target' => '0',
'compareString' => 'word',
),
5 =>
array (
'description' => 'bird is the word, for real',
'criteria' => 'EQUALS',
'testString' => 'bird is the word',
'target' => '0',
'compareString' => 'bird is the word',
),
6 =>
array (
'description' => 'no result',
'criteria' => 'IS_NULL',
'testString' => 'fishing',
'target' => '0',
'compareString' => NULL,
),
),
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/regex",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"Expect:"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"regex": "\\w+",
"testString": "bird is the word",
"flags": "g",
"delimiter": "@",
"flavor": "pcre",
"unitTests": [{
"description": "testing ok festering not ok",
"criteria": "DOES_NOT_MATCH",
"target": "REGEX",
"testString": "festering"
}, {
"description": "word should match",
"criteria": "DOES_MATCH",
"testString": "awesomelicious",
"target": "REGEX"
}, {
"description": "match starts with",
"criteria": "STARTS_WITH",
"testString": "bird",
"target": "0",
"compareString": "bird"
}, {
"description": "match ends with",
"criteria": "ENDS_WITH",
"testString": "poop",
"target": "0",
"compareString": "poop"
}, {
"description": "there should be a word in here somewhere",
"criteria": "CONTAINS",
"testString": "word",
"target": "0",
"compareString": "word"
}, {
"description": "bird is the word, for real",
"criteria": "EQUALS",
"testString": "bird is the word",
"target": "0",
"compareString": "bird is the word"
}, {
"description": "no result",
"criteria": "IS_NULL",
"testString": "fishing",
"target": "0",
"compareString": null
}]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://regex101.com/api/regex");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "POST",
"hostname": "regex101.com",
"port": null,
"path": "/api/regex",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ regex: '\\w+',
testString: 'bird is the word',
flags: 'g',
delimiter: '@',
flavor: 'pcre',
unitTests:
[ { description: 'testing ok festering not ok',
criteria: 'DOES_NOT_MATCH',
target: 'REGEX',
testString: 'festering' },
{ description: 'word should match',
criteria: 'DOES_MATCH',
testString: 'awesomelicious',
target: 'REGEX' },
{ description: 'match starts with',
criteria: 'STARTS_WITH',
testString: 'bird',
target: '0',
compareString: 'bird' },
{ description: 'match ends with',
criteria: 'ENDS_WITH',
testString: 'poop',
target: '0',
compareString: 'poop' },
{ description: 'there should be a word in here somewhere',
criteria: 'CONTAINS',
testString: 'word',
target: '0',
compareString: 'word' },
{ description: 'bird is the word, for real',
criteria: 'EQUALS',
testString: 'bird is the word',
target: '0',
compareString: 'bird is the word' },
{ description: 'no result',
criteria: 'IS_NULL',
testString: 'fishing',
target: '0',
compareString: null } ] }));
req.end();
####Python
import requests
url = "https://regex101.com/api/regex"
payload = " {\n \"regex\":\"\\\\w+\",\n \"testString\":\"bird is the word\",\n \"flags\":\"g\",\n \"delimiter\":\"@\",\n \"flavor\":\"pcre\",\n \"unitTests\":[\n {\n \"description\":\"testing ok festering not ok\",\n \"criteria\":\"DOES_NOT_MATCH\",\n \"target\":\"REGEX\",\n \"testString\":\"festering\"\n },\n {\n \"description\":\"word should match\",\n \"criteria\":\"DOES_MATCH\",\n \"testString\":\"awesomelicious\",\n \"target\":\"REGEX\"\n },\n {\n \"description\":\"match starts with\",\n \"criteria\":\"STARTS_WITH\",\n \"testString\":\"bird\",\n \"target\":\"0\",\n \"compareString\":\"bird\"\n },\n {\n \"description\":\"match ends with\",\n \"criteria\":\"ENDS_WITH\",\n \"testString\":\"poop\",\n \"target\":\"0\",\n \"compareString\":\"poop\"\n },\n {\n \"description\":\"there should be a word in here somewhere\",\n \"criteria\":\"CONTAINS\",\n \"testString\":\"word\",\n \"target\":\"0\",\n \"compareString\":\"word\"\n },\n {\n \"description\":\"bird is the word, for real\",\n \"criteria\":\"EQUALS\",\n \"testString\":\"bird is the word\",\n \"target\":\"0\",\n \"compareString\":\"bird is the word\"\n },\n {\n \"description\":\"no result\",\n \"criteria\":\"IS_NULL\",\n \"testString\":\"fishing\",\n \"target\":\"0\",\n \"compareString\":null\n }\n ]\n}"
headers = {'content-type': 'application/json'}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"permalinkFragment": "FNTZ51",
"version": 1,
"isLibraryEntry": false
}
###Error Response 404
{"error": "Error Message Here (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)"}
##✪ Update an Entry [⇧](#table-of-contents)
URL | Method | content-type |
---|---|---|
/api/regex | POST | application/json |
###Required Parameters:
- regex: your regular expression
- flags: flags to be enabled for this regular expression
-
delimiter: delimiter character to be used, i.e.
"
, or@
, or/
-
flavor: desired regular expression engine, i.e.
pcre
, orpython
, orjavascript
, etc. -
permalinkFragment: the unique ID for the entry you wish to update.
Note: If this parameter is ommitted, a new entry will be created instead.
###Optional Parameters:
- testString: desired test string
- substitution: a substitution pattern for this regex
-
unitTests: JSON array containing each unit test, composed of the following variables:
- description: a description for this unit test
- testString: string to test against using entry's regular expression
- compareString: string to compare resulting match to
-
target: can either be
REGEX
for the entry regex or0
for the entry's resulting match -
criteria: match condition, depending on target; it can be
DOES_MATCH
,DOES_NOT_MATCH
,STARTS_WITH
,ENDS_WITH
,CONTAINS
,EQUALS
orIS_NULL
criteria | explanation | applicable target |
---|---|---|
DOES_MATCH |
assert that the regex matches testString of unit test | REGEX |
DOES_NOT_MATCH |
assert that the regex does not match testString of unit test | REGEX |
STARTS_WITH |
assert that the regex match or selected capture group, given testString of unit test, starts with compareString |
0 or capture group #
|
ENDS_WITH |
assert that the regex match or selected capture group, given testString of unit test, ends with compareString |
0 or capture group #
|
CONTAINS |
assert that the regex match or selected capture group, given testString of unit test, contains compareString |
0 or capture group #
|
EQUALS |
assert that the regex match or selected capture group, given testString of unit test, equals compareString |
0 or capture group #
|
IS_NULL |
assert that the full match or selected capture group, given testString of unit test, does not match or capture anything |
0 or capture group #
|
###Sample call: ####cURL
curl -X POST -H "Expect:" -H "Content-Type: application/json" -d ' {
"regex":"\\w+",
"testString":"bird is the word",
"flags":"g",
"delimiter":"@",
"flavor":"pcre",
"permalinkFragment": "zf3ouS",
"unitTests":[
{
"description":"testing ok festering not ok",
"criteria":"DOES_NOT_MATCH",
"target":"REGEX",
"testString":"festering"
},
{
"description":"word should match",
"criteria":"DOES_MATCH",
"testString":"awesomelicious",
"target":"REGEX"
},
{
"description":"match starts with",
"criteria":"STARTS_WITH",
"testString":"bird",
"target":"0",
"compareString":"bird"
},
{
"description":"match ends with",
"criteria":"ENDS_WITH",
"testString":"poop",
"target":"0",
"compareString":"poop"
},
{
"description":"there should be a word in here somewhere",
"criteria":"CONTAINS",
"testString":"word",
"target":"0",
"compareString":"word"
},
{
"description":"bird is the word, for real",
"criteria":"EQUALS",
"testString":"bird is the word",
"target":"0",
"compareString":"bird is the word"
},
{
"description":"no result",
"criteria":"IS_NULL",
"testString":"fishing",
"target":"0",
"compareString":null
}
]
}' "https://regex101.com/api/regex"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
$fields = array (
'regex' => '\w+',
'testString' => 'bird is the word',
'flags' => 'g',
'delimiter' => '@',
'flavor' => 'pcre',
'permalinkFragment' => 'zf3ouS',
'unitTests' =>
array (
0 =>
array (
'description' => 'testing ok festering not ok',
'criteria' => 'DOES_NOT_MATCH',
'target' => 'REGEX',
'testString' => 'festering',
),
1 =>
array (
'description' => 'word should match',
'criteria' => 'DOES_MATCH',
'testString' => 'awesomelicious',
'target' => 'REGEX',
),
2 =>
array (
'description' => 'match starts with',
'criteria' => 'STARTS_WITH',
'testString' => 'bird',
'target' => '0',
'compareString' => 'bird',
),
3 =>
array (
'description' => 'match ends with',
'criteria' => 'ENDS_WITH',
'testString' => 'poop',
'target' => '0',
'compareString' => 'poop',
),
4 =>
array (
'description' => 'there should be a word in here somewhere',
'criteria' => 'CONTAINS',
'testString' => 'word',
'target' => '0',
'compareString' => 'word',
),
5 =>
array (
'description' => 'bird is the word, for real',
'criteria' => 'EQUALS',
'testString' => 'bird is the word',
'target' => '0',
'compareString' => 'bird is the word',
),
6 =>
array (
'description' => 'no result',
'criteria' => 'IS_NULL',
'testString' => 'fishing',
'target' => '0',
'compareString' => NULL,
),
),
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/regex",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"content-type: application/json",
"expect:"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"regex": "\\w+",
"testString": "bird is the word",
"flags": "g",
"delimiter": "@",
"flavor": "pcre",
"permalinkFragment": "zf3ouS",
"unitTests": [{
"description": "testing ok festering not ok",
"criteria": "DOES_NOT_MATCH",
"target": "REGEX",
"testString": "festering"
}, {
"description": "word should match",
"criteria": "DOES_MATCH",
"testString": "awesomelicious",
"target": "REGEX"
}, {
"description": "match starts with",
"criteria": "STARTS_WITH",
"testString": "bird",
"target": "0",
"compareString": "bird"
}, {
"description": "match ends with",
"criteria": "ENDS_WITH",
"testString": "poop",
"target": "0",
"compareString": "poop"
}, {
"description": "there should be a word in here somewhere",
"criteria": "CONTAINS",
"testString": "word",
"target": "0",
"compareString": "word"
}, {
"description": "bird is the word, for real",
"criteria": "EQUALS",
"testString": "bird is the word",
"target": "0",
"compareString": "bird is the word"
}, {
"description": "no result",
"criteria": "IS_NULL",
"testString": "fishing",
"target": "0",
"compareString": null
}]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://regex101.com/api/regex");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("expect", "");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "POST",
"hostname": "regex101.com",
"port": null,
"path": "/api/regex",
"headers": {
"content-type": "application/json",
"expect": ""
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ regex: '\\w+',
testString: 'bird is the word',
flags: 'g',
delimiter: '@',
flavor: 'pcre',
permalinkFragment: 'zf3ouS',
unitTests:
[ { description: 'testing ok festering not ok',
criteria: 'DOES_NOT_MATCH',
target: 'REGEX',
testString: 'festering' },
{ description: 'word should match',
criteria: 'DOES_MATCH',
testString: 'awesomelicious',
target: 'REGEX' },
{ description: 'match starts with',
criteria: 'STARTS_WITH',
testString: 'bird',
target: '0',
compareString: 'bird' },
{ description: 'match ends with',
criteria: 'ENDS_WITH',
testString: 'poop',
target: '0',
compareString: 'poop' },
{ description: 'there should be a word in here somewhere',
criteria: 'CONTAINS',
testString: 'word',
target: '0',
compareString: 'word' },
{ description: 'bird is the word, for real',
criteria: 'EQUALS',
testString: 'bird is the word',
target: '0',
compareString: 'bird is the word' },
{ description: 'no result',
criteria: 'IS_NULL',
testString: 'fishing',
target: '0',
compareString: null } ] }));
req.end();
####Python
import requests
url = "https://regex101.com/api/regex"
payload = " {\n \"regex\":\"\\\\w+\",\n \"testString\":\"bird is the word\",\n \"flags\":\"g\",\n \"delimiter\":\"@\",\n \"flavor\":\"pcre\",\n \"permalinkFragment\": \"zf3ouS\",\n \"unitTests\":[\n {\n \"description\":\"testing ok festering not ok\",\n \"criteria\":\"DOES_NOT_MATCH\",\n \"target\":\"REGEX\",\n \"testString\":\"festering\"\n },\n {\n \"description\":\"word should match\",\n \"criteria\":\"DOES_MATCH\",\n \"testString\":\"awesomelicious\",\n \"target\":\"REGEX\"\n },\n {\n \"description\":\"match starts with\",\n \"criteria\":\"STARTS_WITH\",\n \"testString\":\"bird\",\n \"target\":\"0\",\n \"compareString\":\"bird\"\n },\n {\n \"description\":\"match ends with\",\n \"criteria\":\"ENDS_WITH\",\n \"testString\":\"poop\",\n \"target\":\"0\",\n \"compareString\":\"poop\"\n },\n {\n \"description\":\"there should be a word in here somewhere\",\n \"criteria\":\"CONTAINS\",\n \"testString\":\"word\",\n \"target\":\"0\",\n \"compareString\":\"word\"\n },\n {\n \"description\":\"bird is the word, for real\",\n \"criteria\":\"EQUALS\",\n \"testString\":\"bird is the word\",\n \"target\":\"0\",\n \"compareString\":\"bird is the word\"\n },\n {\n \"description\":\"no result\",\n \"criteria\":\"IS_NULL\",\n \"testString\":\"fishing\",\n \"target\":\"0\",\n \"compareString\":null\n }\n ]\n}"
headers = {
'content-type': "application/json",
'expect': ""
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"deleteCode": null,
"permalinkFragment": "SMEOqX",
"version": 2,
"isLibraryEntry": false
}
###Error Response 404
{"error": "Error Message Here (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)"}
#✦ Authenticated methods
##✪ Edit Entry Tags ⇧
This method requires authentication.
URL | Method |
---|---|
/apiuser/history/uniqueID/page#/tags | PUT |
###Required Parameters:
-
uniqueID: entry's unique ID
-
page#: page number, using digits; i.e.
1
,2
, and so on. Page number can be obtained by listing all entries first.
-
tags: desired tags
- Note: this is not cumulative, it will replace the tags altogether. If an empty array is sent, all tags will be removed from the entry.
###Optional Parameters:
none
###Sample call: ####cURL
curl -X PUT -H "Content-Type: application/json" \
-d '{"tags":["taggy","wimpy","awesome"]}' "https://regex101.com/api/user/history/YtA4hF/1/tags"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/YtA4hF/1/tags",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"tags\":[\"taggy\",\"wimpy\",\"awesome\"]}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"tags": [
"taggy",
"wimpy",
"awesome"
]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://regex101.com/api/user/history/YtA4hF/1/tags");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "PUT",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/YtA4hF/1/tags",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ tags: [ 'taggy', 'wimpy', 'awesome' ] }));
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/YtA4hF/1/tags"
payload = "{\"tags\":[\"taggy\",\"wimpy\",\"awesome\"]}"
headers = {'content-type': 'application/json'}
response = requests.request("PUT", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"message": "Tags updated"
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ Edit Entry Title [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method |
---|---|
/apiuser/history/uniqueID/page#/title | PUT |
###Required Parameters:
-
uniqueID: entry's unique ID
-
title: desired title
-
page#: this entry's page number, using digits; i.e.
1
,2
, and so on. Page number can be obtained by listing all entries first.
###Optional Parameters:
none
###Sample call: ####cURL
curl -X PUT -H "Content-Type: application/json" \
-d '{"title":"Awesomest Title"}' "https://regex101.com/api/user/history/YtA4hF/1/title"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/YtA4hF/1/title",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"title\":\"Testing now again\"}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"title": "Awesomest Title Here"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://regex101.com/api/user/history/YtA4hF/1/title");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "PUT",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/YtA4hF/1/title",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ title: 'Testing now again' }));
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/YtA4hF/1/title"
payload = "{\"title\":\"Testing now again\"}"
headers = {'content-type': 'application/json'}
response = requests.request("PUT", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"message": "Title updated"
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ Lock or Unlock Entry [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method |
---|---|
/apiuser/history/uniqueID/lock | PUT |
###Required Parameters:
-
uniqueID: entry's unique ID
-
isLocked: can be
true
orfalse
###Optional Parameters:
none
###Sample call: ####cURL
curl -X PUT -H "Content-Type: application/json" \
-d '{"isLocked":"true"}' "https://regex101.com/api/user/history/YtA4hF/lock"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/YtA4hF/lock",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"isLocked\":\"true\"}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"isLocked": "true"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://regex101.com/api/user/history/YtA4hF/lock");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "PUT",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/YtA4hF/lock",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ isLocked: 'true' }));
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/YtA4hF/lock"
payload = "{\"isLocked\":\"true\"}"
headers = {'content-type': 'application/json'}
response = requests.request("PUT", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"message": "Lock status updated"
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ Mark or Unmark Entry as Favorite [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method |
---|---|
/apiuser/favorite/uniqueID/page# | PUT |
###Required Parameters:
-
uniqueID: entry's unique ID
-
isFavorite: changes favorite status for entry with uniqueID specified. Can be
true
orfalse
.
-
page#: page number, using digits; i.e.
1
,2
, and so on. Can be obtained by listing all entries first.
###Optional Parameters:
none
###Sample call: ####cURL
curl -X PUT -H "Content-Type: application/json" \
-d '{"isFavorite":true}' "https://regex101.com/api/user/favorite/Ub4W2T/1"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/favorite/Ub4W2T/1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"isFavorite\":true}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"isFavorite": true
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://regex101.com/api/user/favorite/Ub4W2T/1");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "PUT",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/favorite/Ub4W2T/1",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ isFavorite: true }));
req.end();
####Python
import requests
url = "https://regex101.com/api/user/favorite/Ub4W2T/1"
payload = "{\"isFavorite\":true}"
headers = {'content-type': 'application/json'}
response = requests.request("PUT", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"message": "Favorite status updated"
}
###Error Response 404
{
"error": "Unable to service request (Error Id: d7216117-ce7b-47da-ab77-96a05cc726c4)"
}
##✪ List All User Entries [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method |
---|---|
/api/user/history/all/page# | GET |
/api/user/history/favorites/1/?filterTags=awesome&filterTags=taggy | GET |
###Required Parameters:
-
page#: page number, using digits; i.e.
1
,2
, and so on. Can be obtained by listing all entries first.
###Optional Parameters:
- filterTags: filter results by tags, multiple tags can be passed
###Sample call: ####cURL
curl -X GET "https://regex101.com/api/user/history/all/1/?filterTags=api"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/all/1/?filterTags=api",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/user/history/all/1/?filterTags=api");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/all/1/?filterTags=api",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/all/1/"
querystring = {"filterTags":"api"}
response = requests.request("GET", url, params=querystring)
print(response.text)
###Success Response 200
{
"allTags": [
"taggy",
"awesome",
"api",
"wimpy"
],
"page": 1,
"pages": 1,
"data": [
{
"permalinkFragment": "UbxW2T",
"isPrivate": false,
"isLocked": true,
"version": 1,
"isOwner": true,
"regex": "tester",
"delimiter": "/",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-05T23:48:33.000Z",
"title": "API documentation sample",
"user_data_id": 26946,
"isFavorite": true,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": true,
"tags": [
"api"
]
}
]
}```
###Error Response **`404`**
```js
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ List User Favorite Entries [⇧](#table-of-contents) >**This method requires authentication**.
URL|Method :-:|:-:|:-: /api/user/history/favorites/page#|GET /api/user/history/favorites/1/?filterTags=awesome&filterTags=taggy|GET
###Required Parameters:
-
page#: page number, using digits; i.e.
1
,2
, and so on. Can be obtained by listing all entries first.
###Optional Parameters:
- filterTags: filter results by tags, multiple tags can be passed
###Sample call: ####cURL
curl -X GET "https://regex101.com/api/user/history/favorites/1/?filterTags=api"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/favorites/1/?filterTags=api",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/user/history/favorites/1/?filterTags=api");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/favorites/1/?filterTags=api",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/favorites/1/"
querystring = {"filterTags":"api"}
response = requests.request("GET", url, params=querystring)
print(response.text)
###Success Response 200
{
"allTags": [
"taggy",
"awesome",
"api",
"wimpy"
],
"page": 1,
"pages": 1,
"data": [
{
"permalinkFragment": "UbxW2T",
"isPrivate": false,
"isLocked": true,
"version": 1,
"isOwner": true,
"regex": "tester",
"delimiter": "/",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-05T23:48:33.000Z",
"title": "API documentation sample",
"user_data_id": 26946,
"isFavorite": true,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": true,
"tags": [
"api"
]
}
]
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ List User Authored Entries [⇧](#table-of-contents) >**This method requires authentication**.
URL|Method :-:|:-:|:-: /api/user/history/mine/page#|GET /api/user/history/mine/1/?filterTags=awesome&filterTags=taggy|GET ###Required Parameters:
-
page#: page number, using digits; i.e.
1
,2
, and so on. Can be obtained by listing all entries first.
###Optional Parameters:
- filterTags: filter results by tags, multiple tags can be passed
###Sample call: ####cURL
curl -X GET "https://regex101.com/api/user/history/mine/1/?filterTags=taggy"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/mine/1/?filterTags=taggy",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/user/history/mine/1/?filterTags=taggy");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/mine/1/?filterTags=taggy",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/mine/1/"
querystring = {"filterTags":"taggy"}
response = requests.request("GET", url, params=querystring)
print(response.text)
###Success Response 200
{
"allTags": [
"taggy",
"awesome",
"api",
"wimpy"
],
"page": 1,
"pages": 2,
"data": [
{
"permalinkFragment": "YtA4hF",
"isPrivate": false,
"isLocked": true,
"version": 1,
"isOwner": true,
"regex": "(\\w+)(2)?",
"delimiter": "@",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-07T03:46:35.000Z",
"title": "look ma, no hands",
"user_data_id": 27113,
"isFavorite": false,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": true,
"tags": [
"taggy",
"wimpy",
"awesome"
]
},
{
"permalinkFragment": "fT1vgb",
"isPrivate": false,
"isLocked": false,
"version": 3,
"isOwner": true,
"regex": "\\b(?:word|attractive|some|become)\\b",
"delimiter": "/",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-05T13:05:10.000Z",
"title": null,
"user_data_id": 26861,
"isFavorite": false,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": false,
"tags": []
}
]
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
##✪ List All User Library Entries [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method |
---|---|
/api/user/history/library/page# | GET |
/api/user/history/library/1/?filterTags=awesome&filterTags=taggy | GET |
###Required Parameters:
-
page#: page number, using digits; i.e.
1
,2
, and so on. Number of pages is in the response.
###Optional Parameters:
- filterTags: filter results by tags, multiple tags can be passed
###Sample call: ####cURL
curl -X GET "https://regex101.com/api/user/history/library/1"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/user/history/library/1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/user/history/library/1");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/user/history/library/1",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/user/history/library/1"
response = requests.request("GET", url)
print(response.text)
###Success Response 200
{
"allTags": [
"taggy",
"api"
],
"page": 1,
"pages": 1,
"data": [
{
"permalinkFragment": "YtA4hF",
"isPrivate": false,
"isLocked": true,
"version": 1,
"isOwner": true,
"regex": "(\\w+)(2)?",
"delimiter": "@",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-07T03:46:35.000Z",
"title": null,
"user_data_id": 27113,
"isFavorite": false,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": true,
"tags": []
},
{
"permalinkFragment": "UbxW2T",
"isPrivate": false,
"isLocked": true,
"version": 1,
"isOwner": true,
"regex": "tester",
"delimiter": "/",
"flags": "g",
"flavor": "pcre",
"dateAdded": "2016-10-05T23:48:33.000Z",
"title": "API documentation sample",
"user_data_id": 26946,
"isFavorite": false,
"deleteCode": "00f0lICHYn0J0Q000TVxXKdR",
"isLibraryEntry": true,
"tags": [
"api"
]
}
]
}
###Error Response 404
{"error": "Error Message Here (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)"}
##✪ Publish an Entry to the Library [⇧](#table-of-contents) >**This method requires authentication**.
URL | Method | content-type |
---|---|---|
/api/library | POST | application/json |
This method will return a permalinkFragment
which is the entry's unique ID with which you can build both an edit and a library url: https://regex101.com/r/UbxW2T/1 and https://regex101.com/library/UbxW2T
###Required Parameters:
Include the following in the POST request:
- regex: your regular expression
- flags: flags to be enabled for this regular expression
-
delimiter: delimiter character to be used, i.e.
"
, or@
, or/
-
flavor: desired regular expression engine, i.e.
pcre
, orpython
, orjavascript
, etc. - title: desired title for this library entry
- description: a description for this regex
###Optional Parameters:
- author: author's name
- testString: desired test string
- substitution: a substitution pattern for this regex
-
unitTests: JSON array containing each unit test, composed of the following variables:
- description: a description for this unit test
- testString: string to test against using entry's regular expression
- compareString: string to compare resulting match to
-
target: can either be
REGEX
for the entry regex or0
for the entry's resulting match -
criteria: match condition, depending on target; it can be
DOES_MATCH
,DOES_NOT_MATCH
,STARTS_WITH
,ENDS_WITH
,CONTAINS
,EQUALS
orIS_NULL
criteria | explanation | applicable target |
---|---|---|
DOES_MATCH |
assert that the regex matches testString of unit test | REGEX |
DOES_NOT_MATCH |
assert that the regex does not match testString of unit test | REGEX |
STARTS_WITH |
assert that the regex match or selected capture group, given testString of unit test, starts with compareString |
0 or capture group #
|
ENDS_WITH |
assert that the regex match or selected capture group, given testString of unit test, ends with compareString |
0 or capture group #
|
CONTAINS |
assert that the regex match or selected capture group, given testString of unit test, contains compareString |
0 or capture group #
|
EQUALS |
assert that the regex match or selected capture group, given testString of unit test, equals compareString |
0 or capture group #
|
IS_NULL |
assert that the full match or selected capture group, given testString of unit test, does not match or capture anything |
0 or capture group #
|
###Sample call: ####cURL
curl -X POST -H "Content-Type: application/json" -d ' {
"regex":"(\\w+)(2)?",
"testString":"bird is the word",
"flags":"g",
"delimiter":"@",
"title":"My awesome title",
"description":"My even more awesome description",
"author":"JohnDoe2",
"flavor":"pcre",
"unitTests":[
{
"description":"testing ok festering not ok",
"criteria":"DOES_NOT_MATCH",
"target":"REGEX",
"testString":"festering"
},
{
"description":"word should match",
"criteria":"DOES_MATCH",
"testString":"awesomelicious",
"target":"REGEX"
},
{
"description":"match starts with",
"criteria":"STARTS_WITH",
"testString":"bird",
"target":"0",
"compareString":"bird"
},
{
"description":"match ends with",
"criteria":"ENDS_WITH",
"testString":"poop",
"target":"0",
"compareString":"poop"
},
{
"description":"there should be a word in here somewhere",
"criteria":"CONTAINS",
"testString":"word",
"target":"0",
"compareString":"word"
},
{
"description":"bird is the word, for real",
"criteria":"EQUALS",
"testString":"bird is the word",
"target":"0",
"compareString":"bird is the word"
},
{
"description":"no result",
"criteria":"IS_NULL",
"testString":"fishing",
"target":"2",
"compareString":null
}
]
}' "https://regex101.com/api/library"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
$fields = array (
'regex' => '(\w+)(2)?',
'testString' => 'bird is the word',
'flags' => 'g',
'delimiter' => '@',
'title' => 'My awesome title',
'description' => 'My even more awesome description',
'author' => 'JohnDoe2',
'flavor' => 'pcre',
'unitTests' =>
array (
0 =>
array (
'description' => 'testing ok festering not ok',
'criteria' => 'DOES_NOT_MATCH',
'target' => 'REGEX',
'testString' => 'festering',
),
1 =>
array (
'description' => 'word should match',
'criteria' => 'DOES_MATCH',
'testString' => 'awesomelicious',
'target' => 'REGEX',
),
2 =>
array (
'description' => 'match starts with',
'criteria' => 'STARTS_WITH',
'testString' => 'bird',
'target' => '0',
'compareString' => 'bird',
),
3 =>
array (
'description' => 'match ends with',
'criteria' => 'ENDS_WITH',
'testString' => 'poop',
'target' => '0',
'compareString' => 'poop',
),
4 =>
array (
'description' => 'there should be a word in here somewhere',
'criteria' => 'CONTAINS',
'testString' => 'word',
'target' => '0',
'compareString' => 'word',
),
5 =>
array (
'description' => 'bird is the word, for real',
'criteria' => 'EQUALS',
'testString' => 'bird is the word',
'target' => '0',
'compareString' => 'bird is the word',
),
6 =>
array (
'description' => 'no result',
'criteria' => 'IS_NULL',
'testString' => 'fishing',
'target' => '2',
'compareString' => NULL,
),
),
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/library",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = JSON.stringify({
"regex": "(\\w+)(2)?",
"testString": "bird is the word",
"flags": "g",
"delimiter": "@",
"title": "My awesome title",
"description": "My even more awesome description",
"author": "JohnDoe2",
"flavor": "pcre",
"unitTests": [{
"description": "testing ok festering not ok",
"criteria": "DOES_NOT_MATCH",
"target": "REGEX",
"testString": "festering"
}, {
"description": "word should match",
"criteria": "DOES_MATCH",
"testString": "awesomelicious",
"target": "REGEX"
}, {
"description": "match starts with",
"criteria": "STARTS_WITH",
"testString": "bird",
"target": "0",
"compareString": "bird"
}, {
"description": "match ends with",
"criteria": "ENDS_WITH",
"testString": "poop",
"target": "0",
"compareString": "poop"
}, {
"description": "there should be a word in here somewhere",
"criteria": "CONTAINS",
"testString": "word",
"target": "0",
"compareString": "word"
}, {
"description": "bird is the word, for real",
"criteria": "EQUALS",
"testString": "bird is the word",
"target": "0",
"compareString": "bird is the word"
}, {
"description": "no result",
"criteria": "IS_NULL",
"testString": "fishing",
"target": "2",
"compareString": null
}]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://regex101.com/api/library");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "POST",
"hostname": "regex101.com",
"port": null,
"path": "/api/library",
"headers": {
"content-type": "application/json"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ regex: '(\\w+)(2)?',
testString: 'bird is the word',
flags: 'g',
delimiter: '@',
title: 'My awesome title',
description: 'My even more awesome description',
author: 'JohnDoe2',
flavor: 'pcre',
unitTests:
[ { description: 'testing ok festering not ok',
criteria: 'DOES_NOT_MATCH',
target: 'REGEX',
testString: 'festering' },
{ description: 'word should match',
criteria: 'DOES_MATCH',
testString: 'awesomelicious',
target: 'REGEX' },
{ description: 'match starts with',
criteria: 'STARTS_WITH',
testString: 'bird',
target: '0',
compareString: 'bird' },
{ description: 'match ends with',
criteria: 'ENDS_WITH',
testString: 'poop',
target: '0',
compareString: 'poop' },
{ description: 'there should be a word in here somewhere',
criteria: 'CONTAINS',
testString: 'word',
target: '0',
compareString: 'word' },
{ description: 'bird is the word, for real',
criteria: 'EQUALS',
testString: 'bird is the word',
target: '0',
compareString: 'bird is the word' },
{ description: 'no result',
criteria: 'IS_NULL',
testString: 'fishing',
target: '2',
compareString: null } ] }));
req.end();
####Python
import requests
url = "https://regex101.com/api/library"
payload = " {\n \"regex\":\"(\\\\w+)(2)?\",\n \"testString\":\"bird is the word\",\n \"flags\":\"g\",\n \"delimiter\":\"@\",\n \"title\":\"My awesome title\",\n \"description\":\"My even more awesome description\",\n \"author\":\"JohnDoe2\",\n \"flavor\":\"pcre\",\n \"unitTests\":[\n {\n \"description\":\"testing ok festering not ok\",\n \"criteria\":\"DOES_NOT_MATCH\",\n \"target\":\"REGEX\",\n \"testString\":\"festering\"\n },\n {\n \"description\":\"word should match\",\n \"criteria\":\"DOES_MATCH\",\n \"testString\":\"awesomelicious\",\n \"target\":\"REGEX\"\n },\n {\n \"description\":\"match starts with\",\n \"criteria\":\"STARTS_WITH\",\n \"testString\":\"bird\",\n \"target\":\"0\",\n \"compareString\":\"bird\"\n },\n {\n \"description\":\"match ends with\",\n \"criteria\":\"ENDS_WITH\",\n \"testString\":\"poop\",\n \"target\":\"0\",\n \"compareString\":\"poop\"\n },\n {\n \"description\":\"there should be a word in here somewhere\",\n \"criteria\":\"CONTAINS\",\n \"testString\":\"word\",\n \"target\":\"0\",\n \"compareString\":\"word\"\n },\n {\n \"description\":\"bird is the word, for real\",\n \"criteria\":\"EQUALS\",\n \"testString\":\"bird is the word\",\n \"target\":\"0\",\n \"compareString\":\"bird is the word\"\n },\n {\n \"description\":\"no result\",\n \"criteria\":\"IS_NULL\",\n \"testString\":\"fishing\",\n \"target\":\"2\",\n \"compareString\":null\n }\n ]\n}"
headers = {'content-type': 'application/json'}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
###Success Response 200
{
"permalinkFragment": "UbxW2T",
}
###Error Response 404
{"error": "Error Message Here (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)"}
##✪ List and/or Search All Library Entries [⇧](#table-of-contents) >**This method requires authentication**.
URL|Method :-:|:-:|:-: /api/library/page#|GET /api/library/1/?search=keyword+here&order=MOST_POINTS&filterFlavors=pcre|GET ###Required Parameters:
-
page#: page number, using digits; i.e.
1
,2
, and so on. Can be obtained by listing all entries first.
###Optional Parameters:
-
search: desired search keywords
-
order: order results, values can be
MOST_POINTS
,MOST_RECENT
,LEAST_POINTS
-
filterFlavors: filter results by flavor:
pcre
,javascript
,golang
,python
- Note: flavors can be combined
###Sample call: ####cURL
curl -X GET "https://regex101.com/api/library/1/?search=awesome+title"
See this sample call in other languages
####PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://regex101.com/api/library/1/?search=awesome%20title",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
####JavaScript
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://regex101.com/api/library/1/?search=awesome%20title");
xhr.send(data);
####nodeJS
var http = require("https");
var options = {
"method": "GET",
"hostname": "regex101.com",
"port": null,
"path": "/api/library/1/?search=awesome%20title",
"headers": {}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
####Python
import requests
url = "https://regex101.com/api/library/1/"
querystring = {"search":"awesome title"}
response = requests.request("GET", url, params=querystring)
print(response.text)
###Success Response 200
{
"data": [
{
"title": "My awesome title",
"description": "My even more awesome description",
"dateModified": "2016-10-07T03:46:35.000Z",
"author": "JohnDoe2",
"regex": "(\\w+)(2)?",
"delimiter": "@",
"flavor": "pcre",
"flags": "g",
"version": 1,
"permalinkFragment": "YtA4hF",
"upvotes": 0,
"downvotes": 0,
"userVote": null
}
],
"page": 1,
"pages": 1
}
###Error Response 404
{"error":"Error message here (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)"}
#Limitations Please keep in mind that there are limits to the number of API requests you can make per second. Although this may change without notifications, a good number to keep in mind is 2 requests per second.
#Contact If you bump into any errors while using the API, please open a new GitHub issue.