### Regex101 API Request Examples Source: https://github.com/firasdib/regex101/wiki/API Examples for submitting regex patterns and unit tests to the Regex101 API endpoint. ```bash 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" ``` ```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; } ``` -------------------------------- ### Example Regex Unit Tests Source: https://context7.com/firasdib/regex101/llms.txt Provides an example array of unit tests, demonstrating how to structure tests with descriptions, criteria, targets, input strings, and comparison strings. ```javascript // Example unit tests array: const unitTests = [ { description: "Should match valid email", criteria: "DOES_MATCH", target: "REGEX", testString: "user@example.com" }, { description: "Domain should be captured", criteria: "EQUALS", target: "1", // First capture group testString: "user@example.com", compareString: "example.com" }, { description: "Should not match invalid input", criteria: "DOES_NOT_MATCH", target: "REGEX", testString: "not-an-email" } ]; ``` -------------------------------- ### API Response Examples Source: https://github.com/firasdib/regex101/wiki/API Standard JSON responses for successful and failed API requests. ```json { "deleteCode": null, "permalinkFragment": "SMEOqX", "version": 2, "isLibraryEntry": false } ``` ```json { "error": " (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)" } ``` ```json { "message": "Tags updated" } ``` -------------------------------- ### API Response Examples Source: https://github.com/firasdib/regex101/wiki/API JSON structures for successful and error responses from the API. ```json { "message": "Private status updated" } ``` ```json { "error": " (Error Id: d7216117-ce7b-47da-ab77-96a05cc726c4)" } ``` -------------------------------- ### API Response Examples Source: https://github.com/firasdib/regex101/wiki/API JSON structures returned by the API for successful and failed requests. ```json { "deleteCode": "00f0lICHYn0J0Q000TVxXKdR", "permalinkFragment": "FNTZ51", "version": 1, "isLibraryEntry": false } ``` ```json { "error": " (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)" } ``` -------------------------------- ### List User Favorites API Calls Source: https://github.com/firasdib/regex101/wiki/API Examples for retrieving user favorite entries using various programming languages. ```php curl -X GET "https://regex101.com/api/user/history/favorites/1/?filterTags=api" ``` ```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); ``` ```javascript 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) ``` -------------------------------- ### Fetch User Library Entries (JavaScript) Source: https://github.com/firasdib/regex101/wiki/API An XMLHttpRequest example in JavaScript to fetch user library entries from the Regex101 API. It logs the response text to the console. ```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); ``` -------------------------------- ### List User Authored Entries API Calls Source: https://github.com/firasdib/regex101/wiki/API Examples for retrieving user authored entries using various programming languages. ```php curl -X GET "https://regex101.com/api/user/history/mine/1/?filterTags=taggy" ``` ```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); ``` -------------------------------- ### GET /api/library/{page} Source: https://github.com/firasdib/regex101/wiki/API Retrieve a list of library entries or search for specific regex patterns. ```APIDOC ## GET /api/library/{page} ### Description List and/or search all library entries. You can filter by keywords, order by points, or filter by specific flavors. ### Method GET ### Endpoint /api/library/{page} ### Parameters #### Path Parameters - **page** (integer) - Required - The page number to retrieve. #### Query Parameters - **search** (string) - Optional - Keyword to search for. - **order** (string) - Optional - Sorting order (e.g., MOST_POINTS). - **filterFlavors** (string) - Optional - Filter by regex flavor (e.g., pcre). ### Request Example GET /api/library/1?search=keyword+here&order=MOST_POINTS&filterFlavors=pcre ``` -------------------------------- ### API Response Formats Source: https://github.com/firasdib/regex101/wiki/API Examples of JSON responses returned by the API for successful requests and error conditions. ```json { "permalinkFragment": "UbxW2T" } ``` ```json { "error": " (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)" } ``` -------------------------------- ### List Entries Success Response Source: https://github.com/firasdib/regex101/wiki/API Example JSON response body for a successful history retrieval request. ```json { "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", "isFavorite": true, "deleteCode": "00f0lICHYn0J0Q000TVxXKdR", "isLibraryEntry": true, "tags": [ "api" ] } ] } ``` -------------------------------- ### GET /api/user/history/mine/# Source: https://github.com/firasdib/regex101/wiki/API Retrieves a paginated list of regex entries authored by the authenticated user. ```APIDOC ## GET /api/user/history/mine/# ### Description Retrieves a paginated list of regex entries authored by the authenticated user. This method requires authentication. ### Method GET ### Endpoint /api/user/history/mine/# ### Parameters #### Path Parameters - **#** (integer) - Required - Page number. #### Query Parameters - **filterTags** (string) - Optional - Filter results by tags, multiple tags can be passed. ### Response #### Error Response (400) - **error** (string) - Error message with Error Id. ``` -------------------------------- ### Fetch User Library Entries (cURL) Source: https://github.com/firasdib/regex101/wiki/API A cURL command to fetch user library entries from the Regex101 API. This is a basic GET request to the specified URL. ```bash curl -X GET "https://regex101.com/api/user/history/library/1" ``` -------------------------------- ### GET /api/regex/{id}/{version} Source: https://context7.com/firasdib/regex101/llms.txt Fetches a specific regex entry by its unique ID and version number. ```APIDOC ## GET /api/regex/{id}/{version} ### Description Fetches a specific regex entry by its unique ID and version number. ### Method GET ### Endpoint https://regex101.com/api/regex/{id}/{version} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the regex entry. - **version** (integer) - Required - The version number of the regex entry. ### Response #### Success Response (200) - **regex** (string) - The regex pattern. - **testString** (string) - The test string used. - **flags** (string) - Regex flags. - **flavor** (string) - The regex engine flavor. - **unitTests** (array) - List of associated unit tests. #### Response Example { "regex": "testing \\w+", "testString": "testing retrieval", "flags": "gs", "flavor": "pcre", "unitTests": [] } ``` -------------------------------- ### GET /api/library/{id}/ Source: https://github.com/firasdib/regex101/wiki/API Retrieves a list of regex patterns from the library, with optional search and filtering capabilities. ```APIDOC ## GET /api/library/{id}/ ### Description Retrieves a list of regex patterns from the library. You can filter and sort the results using query parameters. ### Method GET ### Endpoint /api/library/{id}/ ### Query Parameters - **search** (string) - Optional - Keywords to search for within the regex titles or descriptions. - **order** (string) - Optional - Specifies the order of the results. Accepted values: `MOST_POINTS`, `MOST_RECENT`, `LEAST_POINTS`. - **filterFlavors** (string) - Optional - Filters results by regex flavor. Multiple flavors can be combined (e.g., `pcre,javascript`). Accepted values: `pcre`, `javascript`, `golang`, `python`. ### Request Example ```json { "example": "GET https://regex101.com/api/library/1/?search=awesome+title&order=MOST_RECENT&filterFlavors=pcre,python" } ``` ### Success Response (200) - **data** (array) - An array of regex objects. - **title** (string) - The title of the regex. - **description** (string) - The description of the regex. - **dateModified** (string) - The date the regex was last modified. - **author** (string) - The username of the author. - **flavor** (string) - The regex flavor used. - **version** (integer) - The version of the regex. - **permalinkFragment** (string) - A unique fragment for the permalink. - **upvotes** (integer) - The number of upvotes. - **downvotes** (integer) - The number of downvotes. - **userVote** (null) - Indicates if the current user has voted. - **page** (integer) - The current page number of the results. - **pages** (integer) - The total number of pages available. ### Response Example ```json { "data": [ { "title": "My awesome title", "description": "My even more awesome description", "dateModified": "2016-10-07T03:46:35.000Z", "author": "JohnDoe2", "flavor": "pcre", "version": 1, "permalinkFragment": "YtA4hF", "upvotes": 0, "downvotes": 0, "userVote": null } ], "page": 1, "pages": 1 } ``` ### Error Response (400) - **error** (string) - A message describing the error. ### Error Response Example ```json { "error": " (Error Id: 528044b7-854e-46f9-ae92-07786bafa663)" } ``` ``` -------------------------------- ### Search Regex101 Library with PHP Source: https://github.com/firasdib/regex101/wiki/API This PHP script demonstrates how to make a GET request to the Regex101 library API. Ensure cURL is enabled in your PHP environment. ```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; } ``` -------------------------------- ### GET /api/library/{page} Source: https://context7.com/firasdib/regex101/llms.txt Retrieves a paginated list of community library entries with optional search and flavor filtering. ```APIDOC ## GET /api/library/{page} ### Description Retrieves paginated library entries with optional search and filtering by flavor. ### Method GET ### Endpoint https://regex101.com/api/library/{page} ### Parameters #### Path Parameters - **page** (integer) - Required - The page number to retrieve. #### Query Parameters - **search** (string) - Optional - Keywords to search for. - **order** (string) - Optional - Sorting order (e.g., MOST_POINTS). - **filterFlavors** (string) - Optional - Filter by regex flavor (pcre, javascript, golang, python). ### Response #### Success Response (200) - **data** (array) - List of library entries. - **page** (integer) - Current page number. - **pages** (integer) - Total number of pages. #### Response Example { "data": [ { "title": "Email Validation", "description": "Validates email addresses", "dateModified": "2016-10-07T03:46:35.000Z", "author": "JohnDoe2", "flavor": "pcre", "version": 1, "permalinkFragment": "YtA4hF", "upvotes": 42, "downvotes": 3, "userVote": null } ], "page": 1, "pages": 10 } ``` -------------------------------- ### Get Latest Version of Regex Source: https://context7.com/firasdib/regex101/llms.txt Accesses the most recent version of a saved regex by using the /latest endpoint. ```text # Instead of specifying version number: https://regex101.com/r/JvLFcG/3 # Use /latest to always get the newest version: https://regex101.com/r/JvLFcG/latest ``` -------------------------------- ### Success Response - Get Library Entries Source: https://github.com/firasdib/regex101/wiki/API This JSON structure represents a successful response when retrieving library entries. It includes pagination details and a list of matching entries. ```json { "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, "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", "isFavorite": false, "deleteCode": "00f0lICHYn0J0Q000TVxXKdR", "isLibraryEntry": true, "tags": [ "api" ] } ] } ``` -------------------------------- ### Fetch User Library Entries (Python) Source: https://github.com/firasdib/regex101/wiki/API A Python snippet using the 'requests' library to fetch user library entries from the Regex101 API. It makes a simple GET request to the specified URL. ```python import requests url = "https://regex101.com/api/user/history/library/1" response = requests.request("GET", url) print(response.text) ``` -------------------------------- ### Send Regex to Regex101 API with Node.js Source: https://github.com/firasdib/regex101/wiki/API This Node.js example demonstrates how to send a regex pattern and test string to the Regex101 API using the built-in 'https' module. It configures request options and handles the response data. ```javascript 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(); ``` -------------------------------- ### Get Latest Version of Regex Source: https://context7.com/firasdib/regex101/llms.txt Access the most recent version of a saved regex by appending /latest to the URL. ```APIDOC ## GET /r/{regexId}/latest ### Description Access the most recent version of a saved regex by appending `/latest` to the URL. ### Method GET ### Endpoint `/r/{regexId}/latest` ### Parameters #### Path Parameters - **regexId** (string) - Required - The ID of the regex entry. ### Example URL `https://regex101.com/r/JvLFcG/latest` ``` -------------------------------- ### Delete Regex Entry (Node.js) Source: https://github.com/firasdib/regex101/wiki/API This Node.js example demonstrates how to make an HTTP DELETE request to delete a regex entry. ```javascript 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(); ``` -------------------------------- ### Fetch User Library Entries (Node.js) Source: https://github.com/firasdib/regex101/wiki/API This Node.js snippet uses the 'https' module to make a GET request to fetch user library entries from the Regex101 API. It handles the response data and logs it. ```javascript 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(); ``` -------------------------------- ### Edit Entry Title cURL Example Source: https://github.com/firasdib/regex101/wiki/API Sample cURL command to update an entry's title. Requires authentication and specifies the content type as JSON. ```php curl -X PUT -H "Content-Type: application/json" \ -d '{"title":"Awesomest Title"}' "https://regex101.com/api/user/history/YtA4hF/1/title" ``` -------------------------------- ### Edit Entry Title Python Example Source: https://github.com/firasdib/regex101/wiki/API Python script using the 'requests' library to send a PUT request for updating an entry's title. It defines the URL, payload, and headers, then prints the response text. ```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) ``` -------------------------------- ### Edit Entry Title NodeJS Example Source: https://github.com/firasdib/regex101/wiki/API Node.js script using the 'https' module to make a PUT request for updating an entry's title. It constructs the request options and handles the response. ```js 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(); ``` -------------------------------- ### Prefill Interface via URL Source: https://context7.com/firasdib/regex101/llms.txt Configures the regex101 interface fields using query parameters. ```text # URL format for prefilling fields: https://regex101.com/?regex=\w+&testString=hello%20world&flags=gi&delimiter=/ # Parameters: # - regex: The regular expression pattern # - testString: Text to test against # - flags: Regex flags (g, i, m, s, u, x) # - subst: Substitution/replacement string # - delimiter: Delimiter character (/, ~, @, etc.) ``` -------------------------------- ### Create an Entry Source: https://github.com/firasdib/regex101/wiki/API Creates a new regex entry with specified parameters. ```APIDOC ## POST /api/regex ### Description Creates a new regex entry with specified parameters including the regex pattern, flags, flavor, and optional test strings or substitutions. ### Method POST ### Endpoint /api/regex ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **regex** (string) - Required - The regular expression pattern. - **flags** (string) - Required - Flags to be enabled for this regular expression (e.g., 'g', 'i', 'm'). - **delimiter** (string) - Required - Delimiter character to be used (e.g., '/', '~', '`', '"'). - **flavor** (string) - Required - Desired regular expression engine (e.g., 'pcre', 'python', 'javascript', 'golang'). - **testString** (string) - Optional - A string to test the regex against. - **substitution** (string) - Optional - A substitution pattern for this regex. - **unitTests** (array) - Optional - A JSON array containing unit tests. - **description** (string) - Description for the unit test. - **testString** (string) - String to test against. - **compareString** (string) - String to compare the result to. - **target** (string) - Target for the test ('REGEX' or '0' for match group). - **criteria** (string) - Match condition (e.g., 'DOES_MATCH', 'DOES_NOT_MATCH', 'STARTS_WITH', 'ENDS_WITH', 'CONTAINS', 'EQUALS', 'IS_NULL'). ### Request Example ```json { "regex": "(a+)", "flags": "g", "delimiter": "/", "flavor": "pcre", "testString": "aaaaa", "substitution": "$1", "unitTests": [ { "description": "Test for multiple a's", "testString": "aaaaa", "compareString": "a", "target": "0", "criteria": "STARTS_WITH" } ] } ``` ### Response #### Success Response (200) - **message** (string) - Indicates successful creation. - **regexId** (string) - The ID of the created regex. - **url** (string) - The URL to access the created regex. #### Response Example ```json { "message": "Your regex has been created.", "regexId": "/r/AaKDTO/1", "url": "https://regex101.com/r/AaKDTO/1" } ``` #### Error Response (400) - **error** (string) - Describes the error, e.g., 'Invalid input parameters'. #### Error Response Example (400) ```json { "error": "Invalid input parameters (Error Id: ...)" } ``` ``` -------------------------------- ### POST /api/library Source: https://github.com/firasdib/regex101/wiki/API Creates a new entry in the Regex101 library with a regex pattern, configuration, and associated unit tests. ```APIDOC ## POST /api/library ### Description Creates a new entry in the Regex101 library. This endpoint accepts a regex pattern, flavor, flags, and a suite of unit tests to validate the regex behavior. ### Method POST ### Endpoint https://regex101.com/api/library ### Request Body - **regex** (string) - Required - The regular expression pattern. - **testString** (string) - Optional - The default test string. - **flags** (string) - Optional - Regex flags (e.g., 'g', 'i'). - **delimiter** (string) - Optional - The delimiter used for the regex. - **title** (string) - Optional - Title of the library entry. - **description** (string) - Optional - Description of the library entry. - **author** (string) - Optional - The author's name. - **flavor** (string) - Optional - The regex engine flavor (e.g., 'pcre'). - **unitTests** (array) - Optional - A collection of unit tests to validate the regex. ### Request Example { "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": "word should match", "criteria": "DOES_MATCH", "testString": "awesomelicious", "target": "REGEX" } ] } ``` -------------------------------- ### GET /api/user/history/favorites/# Source: https://github.com/firasdib/regex101/wiki/API Retrieves a paginated list of regex entries marked as favorites by the authenticated user. ```APIDOC ## GET /api/user/history/favorites/# ### Description Retrieves a paginated list of regex entries marked as favorites by the authenticated user. This method requires authentication. ### Method GET ### Endpoint /api/user/history/favorites/# ### Parameters #### Path Parameters - **#** (integer) - Required - Page number. #### Query Parameters - **filterTags** (string) - Optional - Filter results by tags, multiple tags can be passed. ### Response #### Success Response (200) - **allTags** (array) - List of all available tags. - **page** (integer) - Current page number. - **pages** (integer) - Total number of pages. - **data** (array) - List of favorite regex entries. #### Error Response (400) - **error** (string) - Error message with Error Id. ``` -------------------------------- ### Prefill Regex101 Fields via URL Source: https://github.com/firasdib/regex101/wiki/FAQ Use query parameters to prefill the regex, test string, flags, replacement, and delimiter fields in the Regex101 interface. Note that permalink content will override these flags. ```url https://regex101.com/?regex=&testString=&flags=&subst=&delimiter= ``` -------------------------------- ### GET /api/regex/{uniqueID}/{revision} Source: https://github.com/firasdib/regex101/wiki/API Retrieves a specific regex entry by its unique ID and revision number. ```APIDOC ## GET /api/regex/{uniqueID}/{revision} ### Description Retrieves a specific regex entry using its unique identifier and revision number. ### Method GET ### Endpoint /api/regex/{uniqueID}/{revision} ### Parameters #### Path Parameters - **uniqueID** (string) - Required - The unique ID of the regex entry. - **revision** (integer) - Required - The revision number of the regex entry. ### Request Example ```json { "example": "GET https://regex101.com/api/regex/AaKDTO/1" } ``` ### Success Response (200) - **regex** (string) - The regex pattern. - **testString** (string) - A sample string used for testing the regex. - **flags** (string) - The flags applied to the regex (e.g., 'gs'). - **delimiter** (string) - The delimiter used for the regex. - **flavor** (string) - The regex flavor. - **substitution** (null) - Placeholder for substitution details (currently null). - **title** (null) - The title of the regex (currently null). - **unitTests** (array) - An array of unit tests associated with the regex. - **description** (string) - Description of the unit test. - **criteria** (string) - The criteria for the test (e.g., 'DOES_NOT_MATCH'). - **target** (string) - The target of the test (e.g., 'REGEX'). - **testString** (string) - The string to test. - **compareString** (null) - Placeholder for comparison string (currently null). - **isFavorite** (boolean) - Indicates if the regex is a favorite of the current user. - **isLibraryEntry** (boolean) - Indicates if the regex is a library entry. ### Response Example ```json { "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 } ``` ``` -------------------------------- ### Implement the CodeString helper class Source: https://github.com/firasdib/regex101/wiki/Writing-a-Code-Generator A utility class for managing indentation and newline concatenation when building code strings. ```javascript class CodeString { constructor(string = '') { this.string = string; this.indentLevel = 0; } indent(str, space = 0) { return ' '.repeat(space) + str; } append(str = '', indentLevel) { this.string += this.indent(`${str}\n`, this.indentLevel); // If `indentLevel` is defined, it will be set until changed later. if (indentLevel != null) { this.indentLevel = indentLevel; } } toString() { return this.string; } } export default CodeString; ``` -------------------------------- ### Publish Regex to Community Library Source: https://context7.com/firasdib/regex101/llms.txt Publishes a regex to the community library, requiring authentication. Includes title, description, and optional unit tests. Authentication is handled via OAuth (GitHub, Google, or Twitter). ```bash curl -X POST -H "Content-Type: application/json" -d '{ "regex": "(\\w+)(2)?", "testString": "bird is the word", "flags": "g", "delimiter": "@", "title": "Word Matcher", "description": "Matches words with optional trailing 2", "author": "JohnDoe2", "flavor": "pcre", "unitTests": [ { "description": "should match words", "criteria": "DOES_MATCH", "testString": "hello", "target": "REGEX" } ] }' "https://regex101.com/api/library" ``` -------------------------------- ### POST /api/regex Source: https://github.com/firasdib/regex101/wiki/API Create a new regex entry with specified parameters and unit tests. ```APIDOC ## POST /api/regex ### Description This endpoint allows you to create a new regex entry. You can provide the regex pattern, test strings, flags, flavor, delimiter, and unit tests. ### Method POST ### Endpoint https://regex101.com/api/regex ### Request Body - **regex** (string) - Required - The regular expression pattern. - **testString** (string) - Required - A string to test the regex against. - **flags** (string) - Optional - Flags for the regex (e.g., 'g' for global). - **delimiter** (string) - Optional - The delimiter used in the regex. - **flavor** (string) - Optional - The regex flavor (e.g., 'pcre', 'python'). - **permalinkFragment** (string) - Optional - A fragment for the permalink. - **unitTests** (array) - Optional - An array of unit test objects. - **description** (string) - Required - Description of the unit test. - **criteria** (string) - Required - The criteria for the test (e.g., 'DOES_MATCH', 'STARTS_WITH'). - **target** (string) - Required - The target for the test. - **testString** (string) - Required - The string to test. - **compareString** (string) - Optional - A string to compare against. ### Request Example ```json { "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 } ] } ``` ### Response #### Success Response (200) - **deleteCode** (null) - Description not provided. - **permalinkFragment** (string) - The fragment for the permalink of the created entry. - **version** (integer) - The version of the created entry. - **isLibraryEntry** (boolean) - Indicates if the entry is a library entry. #### Response Example ```json { "deleteCode": null, "permalinkFragment": "SMEOqX", "version": 2, "isLibraryEntry": false } ``` #### Error Response (400 or 403) - **error** (string) - An error message indicating the reason for failure. #### Error Response Example ```json { "error": " (Error Id: a5844079-8cd6-4b1b-a730-a361facc3aef)" } ``` ``` -------------------------------- ### Prefill Interface via URL Source: https://context7.com/firasdib/regex101/llms.txt Prefill the regex101 interface with specific values using query parameters. ```APIDOC ## GET / ### Description Prefill the regex101 interface with specific values using query parameters. ### Method GET ### Endpoint `/ ### Parameters #### Query Parameters - **regex** (string) - The regular expression pattern. - **testString** (string) - Text to test against. - **flags** (string) - Regex flags (e.g., `g`, `i`, `m`, `s`, `u`, `x`). - **subst** (string) - Substitution/replacement string. - **delimiter** (string) - Delimiter character (e.g., `/`, `~`, `@`). ### Example URL `https://regex101.com/?regex=\w+&testString=hello%20world&flags=gi&delimiter=/` ``` -------------------------------- ### List Library Entries with Search and Filter Source: https://context7.com/firasdib/regex101/llms.txt Retrieves paginated library entries. Supports searching by keywords and filtering by regex flavor (e.g., pcre, javascript, golang, python). ```bash curl -X GET "https://regex101.com/api/library/1" ``` ```bash curl -X GET "https://regex101.com/api/library/1?search=email+validation&order=MOST_POINTS&filterFlavors=pcre" ```