Ir al contenido
POST AI agent ready /v1/regex/generate

Regex Generator API - Natural-Language to Regex Pattern

Matches a natural-language description against a library of pre-vetted patterns (email, URL, phone, date, IPv4, hex color, UUID, credit card, ZIP/postal code). When the description matches a known keyword set the endpoint returns a tested pattern with appropriate flags. Unknown descriptions fall back to an escaped, word-boundary-style pattern. Optional test_string runs the pattern and returns the matched substrings.

Parameters

stringrequired

Plain-English description of what you want to match (e.g., "email address", "hex color").

string

Optional sample text to run the generated pattern against. When provided, the response includes test_result with matches.

Code examples

curl -X POST https://api.botoi.com/v1/regex/generate \
  -H "Content-Type: application/json" \
  -d '{"description":"email address","test_string":"Contact us at sales@example.com or support@example.org"}'

When to use this API

Regex helper in a developer tool

When a user types "match phone numbers" in your form builder, call this endpoint and drop the returned pattern and flags into the validation field. Saves users from hand-crafting regex for common shapes.

Log parsing templates

Generate patterns for UUIDs, IPs, and timestamps on demand, then pipe them into your log-pipeline config. The test_string field lets you confirm the pattern fires on a sample log line before shipping the config.

Quick validation prototypes

During API design, ask for a "credit card" or "ZIP code" pattern and plug the result straight into your Zod or Yup schema. Swap for a stricter pattern later; this gets you a working draft in seconds.

Frequently asked questions

Which descriptions are recognized?
The library covers email, URL (http/https/website/link), phone (telephone/mobile), date, IP (ipv4), hex color (hex code/color code), UUID (guid), credit card, and ZIP/postal codes. Keyword matches are substring and case-insensitive.
What does the endpoint do for unrecognized descriptions?
It escapes your description characters and returns a literal-match pattern with the "i" flag. This is a safe default but not a creative regex synthesizer. For novel patterns, use /v1/regex/test to iterate manually.
Is the generated regex safe to run on untrusted input?
The shipped patterns avoid catastrophic backtracking on common inputs. Still, apply a size limit to any string you feed into the pattern and consider a regex timeout on your side for adversarial loads.
Why does test_result sometimes include the "g" flag?
When you pass test_string the endpoint adds the "g" flag internally so it can collect every match into the found array. The returned pattern keeps the original flags so you can use it unchanged downstream.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.