Docs › Developer tools
Regex tester API
Run a regular expression against a text and see every match, explained.
Tests a pattern in JavaScript or RE2 (Go) syntax: every match with its groups and their character offsets, an optional replacement, and the pattern taken apart token by token in plain words. JavaScript patterns run under a one-second limit, since nested quantifiers can take exponentially long; RE2 cannot. Patterns and texts are not logged or kept. Each request counts as 10 against the rate limit.
Test a regular expression
GET/v1/regexPOST
An invalid pattern answers 422 with code invalid_pattern and the engine's message; a JavaScript pattern that runs out of time answers 422 with code timeout. A group that took no part in a match has a null text, which is different from an empty one.
Also takes POST: The text to test the pattern on (pattern and options in the query), or JSON {"pattern": ..., "text": ...} with the options beside them. Send it as text/plain, or as JSON {"text": "..."} with the other options beside it, up to 256 KB.
What you send here is never written to the log, and the answer is not cached.
| Parameter | Description |
|---|---|
patternquery, required | The regular expression, without slashes. Up to 4096 bytes. |
textquery | The text to test it on (or POST it). |
flavorquery | js (default): JavaScript syntax, with lookaround and backreferences. re2: Go's syntax, linear time. One of: js, re2. |
flagsquery | Any of i (ignore case), m (^ and $ at line breaks), s (. matches line breaks). Every match is always listed, so g is not needed. |
replacequery | Replace every match with this: $1, $<name>, $& and $$ in js; ${1}, ${name} and $$ in re2. |
limitquery | Matches listed, 1 to 1000. Default 100; count goes on to the end of the text. |
curl
curl "https://api.dharun.dev/v1/regex?flags=i&pattern=%28%3F%3Cstate%3E%5BA-Z%5D%7B2%7D%29%5B+-%5D%3F%28%5Cd%7B2%7D%29&text=Cars+TN+37%2C+ka-05+and+MH12"JavaScript
const response = await fetch("https://api.dharun.dev/v1/regex?flags=i&pattern=%28%3F%3Cstate%3E%5BA-Z%5D%7B2%7D%29%5B+-%5D%3F%28%5Cd%7B2%7D%29&text=Cars+TN+37%2C+ka-05+and+MH12");
const body = await response.json();
if (!response.ok) throw new Error(body.error.message);
console.log(body.data);Python
import requests
response = requests.get("https://api.dharun.dev/v1/regex?flags=i&pattern=%28%3F%3Cstate%3E%5BA-Z%5D%7B2%7D%29%5B+-%5D%3F%28%5Cd%7B2%7D%29&text=Cars+TN+37%2C+ka-05+and+MH12", timeout=10)
body = response.json()
if not response.ok:
raise RuntimeError(body["error"]["message"])
print(body["data"])Response, with lists and long text shortened
{
"data": {
"flavor": "js",
"pattern": "(?<state>[A-Z]{2})[ -]?(\\d{2})",
"flags": "i",
"groups": [
{
"index": 1,
"name": "state"
},
{
"index": 2
}
],
"count": 3,
"truncated": false,
"matches": [
{
"text": "TN 37",
"start": 5,
"end": 10,
"groups": [
{
"index": 1,
"name": "state",
"text": "TN",
"start": 5,
"end": 7
},
{
"index": 2,
"text": "37",
"start": 8,
"end": 10
}
]
},
{
"text": "ka-05",
"start": 12,
"end": 17,
"groups": [
{
"index": 1,
"name": "state",
"text": "ka",
"start": 12,
"end": 14
},
{
"index": 2,
"text": "05",
"start": 15,
"end": 17
}
]
},
{
"text": "MH12",
"start": 22,
"end": 26,
"groups": [
{
"index": 1,
"name": "state",
"text": "MH",
"start": 22,
"end": 24
},
{
"index": 2,
"text": "12",
"start": 24,
"end": 26
}
]
}
],
"explanation": [
{
"token": "(?<state>",
"depth": 0,
"meaning": "Start of capturing group 1, named \"state\"."
},
{
"token": "[A-Z]",
"depth": 1,
"meaning": "One character: “A” to “Z”."
},
{
"token": "{2}",
"depth": 1,
"meaning": "Repeats the item before it exactly 2 times."
}
]
},
"meta": {
"note": "JavaScript syntax, run by regexp2 in ECMAScript mode. It agrees with browsers and Node.js in nearly every case; a backreference such as \\1 in a pattern that mix…"
}
}Using an AI assistant? Connect the MCP server and it can call this API by itself.