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.

GETPOSThttps://apibox.io.vn/v1/regex
Developer utilities▶ Try it online

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

NameInTypeRequiredDefault
patternbody|querystringyesThe regular expression, without slashes.
textbody|querystringnoText to search (max 100,000 characters).
flagsbody|querystringnoFlags, e.g. gi.
actionbody|querystringnomatchmatch, test, replace or split.
replacementbody|querystringnoReplacement for replace ($1, $<name>, $&).
limitbody|querynumberno100Max 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"}'

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

Start with 1,000 free requests every month. Get free API key →