Generate a regex
Writing a regular expression from scratch usually means three tabs open, a half-remembered lookahead syntax, and a test case that quietly fails after you ship. This endpoint takes a description of what you're trying to match and returns a working expression along with example strings it does and doesn't match.
Run it online
Run this on our servers with your account. Free tools run in your browser; this one bills your KIT balance per the price above.
The gap between knowing the rule and writing the syntax
Most developers can describe exactly what they need to match — a phone number in three formats, a slug with optional trailing numbers, a log line with a timestamp and a severity level — long before they can recall whether their engine needs a non-capturing group or how to escape a literal dot inside a character class. That gap between the rule in your head and the syntax on the screen is where regular expressions earn their reputation, and it's the exact gap dev.regex_generate closes.
From description to a tested pattern
POST /dev/regex-generate with a plain-language description of the pattern you need — and ideally a couple of example strings that should match and a couple that shouldn't — and the call returns a task_id while the expression is built and verified in the background. The result, delivered by signed webhook or a signed link valid for 24 hours, includes the generated pattern itself plus the test strings it was checked against, so you're not asked to trust an expression you haven't seen exercised.
A syntax older than most of the languages that use it
Regular expressions trace back to formal language theory from the 1950s and reached programmers through Ken Thompson's work on the QED and ed text editors in the 1960s, decades before Perl popularized the dense, symbol-heavy style most developers recognize today. That long history is exactly why the syntax feels inconsistent across languages and engines — lookbehind support, Unicode property escapes and named groups arrived at different times in different implementations, which is part of why even people who know regex well still end up double-checking edge cases against a tester before trusting a pattern in production.
Where it saves the most time
Form validation, log parsing, data extraction from semi-structured text and search-and-replace scripts all lean on regular expressions, and all of them are exactly where a subtly wrong pattern causes quiet failures rather than loud ones — a validation regex that's slightly too permissive lets bad data through instead of rejecting it outright. Because each task is billed per request plus per pattern item and a failed generation is never charged, teams can generate and verify a whole batch of field validators for a form builder, or the parsing patterns for a log ingestion pipeline, in one pass instead of writing and manually testing each one.
What you can do with it
Form field validation
A form builder generates a validation pattern for a phone number field from a plain description of the accepted formats, complete with passing and failing examples.
Log line parsing
A log ingestion pipeline generates a pattern to extract timestamp, severity and message from a custom log format without a developer hand-writing the expression.
Data extraction from semi-structured text
A scraping tool generates a pattern to pull product SKUs in a known but inconsistent format out of scraped page text.
Search-and-replace in a migration script
A code migration script generates a precise pattern to find one API call signature across a codebase before a bulk rename.
FAQ
How do I generate a regex with the API?
POST a plain-language description of the pattern to /dev/regex-generate, keep the returned task_id, and collect the expression and its test cases by webhook or a signed link valid for 24 hours.
Is the regex generator API free?
No, there is no free tier or trial; it costs $0.003 per request plus $0.0135 per item, and a failed generation is never charged.
Does it give me test examples along with the pattern?
Yes, the result includes example strings the pattern matches and example strings it correctly rejects, so you can verify it before using it.
Which regex flavor does it target?
You can specify the target engine or language in your request; describe your use case and any flavor constraints so the generated pattern is compatible with where you'll run it.
Can it generate multiple patterns in one request?
Yes, submit multiple items in one task and each is priced individually at the per-item rate, which suits building a full set of validators at once.
Will the generated regex always be the most efficient one?
It's built to correctly match your description and pass the provided test cases; for extremely performance-sensitive patterns, review it against your specific data volume.
Is this endpoint live?
Yes, /dev/regex-generate is live and accepting requests now.
Is my description or the generated pattern stored?
No, submitted descriptions and generated patterns are deleted after the retention window and are never used for training.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, and soon from our app, email and Telegram.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/dev/regex-generate \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"items":["valor-1","valor-2"]}'const res = await fetch("https://api.kit.forhosting.com/dev/regex-generate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"items": [
"valor-1",
"valor-2"
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/regex-generate",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"items": [
"valor-1",
"valor-2"
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/regex-generate", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"items":["valor-1","valor-2"]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"items":["valor-1","valor-2"]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/regex-generate", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"items": [
"valor-1",
"valor-2"
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.regex_generate",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
422 | task_failed | The task failed after 3 retries. You are never charged for it. |