Regex Creator

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 g flag is always on; you can add i, m, s and u.
  • 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, with truncated: true when 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: userRequest and regex up 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-creator
Get AI help writing, fixing or explaining a regex

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
userRequest
string
Required
What you want, e.g. "Match US phone numbers with optional area code". 1-2000 characters.
regex
string
OptionalAn existing regex to fix or explain. Up to 2000 characters.
exampleText
string
OptionalSample 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 key
403
API key inactive or expired, or request IP not allowed
429
Rate limit exceeded (10 per minute or 200 per day)
500
Internal server error or AI model failure
POST
https://opentools.ca/api/v1/tools/regex-creator/test
Run a regex against text and list the matches (no AI)

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
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
OptionalExtra 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 compile
401
Missing or invalid API key
403
API key inactive or expired, or request IP not allowed
422
The regex took longer than 1 second to run
429
Rate limit exceeded (20 per minute)
500
Internal server error

Code 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"
  }'

Ready to get started?

Create an API key to start using the Regex Creator API.

Rather use it in your browser? Open the Regex Creator