
Regex Creator API
Development
Create and test regular expressions with real-time visualization and AI assistance. Perfect for developers, data scientists, and text processing tasks.
Authentication
All API requests require a valid API key passed in the Authorization header as a Bearer token.
Rate Limit
10 requests per minute
Endpoints
2 endpoints available
Overview
Two endpoints:
- POST /v1/tools/regex-creator: AI help. Describe what you need ("match Canadian postal codes", "why doesn't this match the second line?"), optionally with a regex and sample text, and an AI model writes, fixes or explains the pattern. The answer is text, usually Markdown.
- POST /v1/tools/regex-creator/test: no AI. Runs a JavaScript regular expression against your text and returns every match with its position and capture groups, the same as the page's live tester.
Notes
- The test endpoint uses JavaScript (ECMAScript) regex syntax. The
gflag is always on; you can addi,m,sandu. - Test runs stop after 1 second; a pattern that takes longer (usually nested quantifiers like
(a+)+) returns 422. At most 1,000 matches are returned, withtruncated: truewhen there were more. - Unmatched optional capture groups come back as
null. - AI help is an AI endpoint: 10 requests per minute and 200 per day per API key. Your request, regex and sample text are sent to a third-party AI model.
- The test endpoint allows 20 requests per minute per API key.
- Limits:
userRequestandregexup to 2,000 characters; sample text up to 20,000 characters for AI help and 100,000 for test.
Endpoints
POST
https://opentools.ca/api/v1/tools/regex-creatorGet AI help writing, fixing or explaining a regex
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| userRequest | string | Required | What you want, e.g. "Match US phone numbers with optional area code". 1-2000 characters. |
| regex | string | Optional | An existing regex to fix or explain. Up to 2000 characters. |
| exampleText | string | Optional | Sample text the regex should work on. Up to 20000 characters. |
Response Example
{
"success": true,
"answer": "Here is a regex for Canadian postal codes:\n\n```\n^[A-Za-z]\\d[A-Za-z][ -]?\\d[A-Za-z]\\d$\n```\n\nIt matches a letter, digit, letter, an optional space or hyphen, then digit, letter, digit. Against your sample text it matches \"K1A 0B1\" and \"M5V-2T6\" but not \"12345\"."
}Error Codes
400
Invalid JSON or invalid parameters (see details)401
Missing or invalid API key403
API key inactive or expired, or request IP not allowed429
Rate limit exceeded (10 per minute or 200 per day)500
Internal server error or AI model failurePOST
https://opentools.ca/api/v1/tools/regex-creator/testRun a regex against text and list the matches (no AI)
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| regex | string | Required | JavaScript regex pattern without slashes, e.g. "(\\d{3})-(\\d{4})" in JSON. 1-2000 characters. |
| text | string | Required | Text to search. Up to 100000 characters. |
| flags | string | Optional | Extra flags from "gimsu", e.g. "i". "g" is always added. |
Response Example
{
"success": true,
"regex": "(\\d{3})-(\\d{4})",
"flags": "g",
"matchCount": 2,
"truncated": false,
"matches": [
{
"match": "555-1234",
"index": 5,
"groups": [
"555",
"1234"
]
},
{
"match": "555-9876",
"index": 17,
"groups": [
"555",
"9876"
]
}
]
}Error Codes
400
Invalid JSON, invalid parameters, or the regex does not compile401
Missing or invalid API key403
API key inactive or expired, or request IP not allowed422
The regex took longer than 1 second to run429
Rate limit exceeded (20 per minute)500
Internal server errorCode Examples
# AI help
curl -X POST https://opentools.ca/api/v1/tools/regex-creator \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"userRequest": "Match Canadian postal codes, with or without the space",
"exampleText": "K1A 0B1\nM5V-2T6\n12345"
}'
# Test a regex (no AI)
curl -X POST https://opentools.ca/api/v1/tools/regex-creator/test \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"regex": "(\\d{3})-(\\d{4})",
"text": "Call 555-1234 or 555-9876"
}'Rather use it in your browser? Open the Regex Creator