Regex Tester API
Run a JavaScript regular expression on text: all matches with positions, numbered and named groups, replace and split, with protection against runaway patterns.
The regex API runs a regular expression (JavaScript / ECMAScript syntax, as in browsers and Node.js) on a text of up to 100,000 characters. action=match (the default) returns every match with its start and end position and the value and position of each numbered and named group; test returns true / false, replace applies a replacement with $1, $<name> and $&, and split splits the text.
Flags are the usual g i m s u v y (and d, used internally for group positions). Without g, match returns the first match only. Invalid patterns return a 400 with the error of the engine, so the API also works as a validator for patterns typed by users.
Patterns with a nested quantifier such as (a+)+ or (\w*\s?)*, which can take exponential time on some inputs, are rejected with unsafe_pattern. Results are limited to 1,000 matches (limit, default 100); count still gives the total.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
pattern | body|query | string | yes | The regular expression, without slashes. | |
text | body|query | string | no | Text to search (max 100,000 characters). | |
flags | body|query | string | no | Flags, e.g. gi. | |
action | body|query | string | no | match | match, test, replace or split. |
replacement | body|query | string | no | Replacement for replace ($1, $<name>, $&). | |
limit | body|query | number | no | 100 | Max matches / parts returned (1–1000). |
Example
curl -X POST "https://apibox.io.vn/v1/regex" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"pattern":"(?<user>[\\w.]+)@([\\w.]+)","flags":"g","text":"a@x.com, b.c@y.vn"}'const res = await fetch('https://apibox.io.vn/v1/regex', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"pattern": "(?<user>[\\w.]+)@([\\w.]+)",
"flags": "g",
"text": "a@x.com, b.c@y.vn"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/regex",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"pattern": "(?<user>[\\w.]+)@([\\w.]+)", "flags": "g", "text": "a@x.com, b.c@y.vn"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/regex');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"pattern":"(?<user>[\\\\w.]+)@([\\\\w.]+)","flags":"g","text":"a@x.com, b.c@y.vn"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"pattern": "(?<user>[\\w.]+)@([\\w.]+)",
"flags": "g",
"action": "match",
"group_count": 2,
"group_names": [
"user"
],
"global": true,
"count": 2,
"truncated": false,
"matches": [
{
"match": "a@x.com",
"index": 0,
"end": 7,
"groups": [
{
"index": 1,
"value": "a",
"start": 0,
"end": 1
},
{
"index": 2,
"value": "x.com",
"start": 2,
"end": 7
}
],
"named": {
"user": "a"
}
},
{
"match": "b.c@y.vn",
"index": 9,
"end": 17,
"groups": [
{
"index": 1,
"value": "b.c",
"start": 9,
"end": 12
},
{
"index": 2,
"value": "y.vn",
"start": 13,
"end": 17
}
],
"named": {
"user": "b.c"
}
}
]
}
Use cases
- Regex playgrounds and teaching tools
- Validate user-supplied patterns before saving them
- Extract data from logs or text in no-code automations
- Bulk find-and-replace from scripts in any language
FAQ
Which regex flavour is used?
ECMAScript (V8), like JavaScript in browsers and Node.js. Lookbehind, named groups, Unicode property escapes (\p{L} with the u flag) and the v flag are supported.
Why was my pattern rejected as unsafe?
It has a quantified group containing another quantifier, the classic cause of catastrophic backtracking. Rewrite it (for example (a+)+ → a+) or use atomic alternatives.
How do I reference groups in a replacement?
$1, $2… for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal $.
Related APIs
UUID Generator
Generate up to 1,000 UUID v4, time-ordered UUID v7, ULID, Nano ID or random hex IDs per request. Secure randomness, optional uppercase.
⏱Cron Expression Parser
Validate a cron expression and get its next run times in any timezone, with a plain-English description. Supports 5, 6 and 7-field cron syntax.
🕒Time & Timezone Converter
Get the current time in any timezone, convert between timezones and Unix timestamps (seconds or ms), with UTC offset and weekday for up to 30 zones.