---
title: "Test a regular expression"
method: POST
path: "/v1/regex"
tags: ["Regex tester"]
---

# Test a regular expression

`POST /v1/regex`

## Request

- Base URL: `https://api.dharun.dev`
- URL: `https://api.dharun.dev/v1/regex`
- Auth: none declared

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.

## Query parameters

- `pattern` string
- `flavor` 'js' | 're2'
- `flags` string
- `replace` string
- `limit` integer

## Request body

- object
  - `flags` string: Any of i (ignore case), m (^ and $ at line breaks), s (. matches line breaks). Every match is always listed, so g is not needed.
  - `flavor` 'js' | 're2': js (default): JavaScript syntax, with lookaround and backreferences. re2: Go's syntax, linear time.
  - `limit` integer: Matches listed, 1 to 1000. Default 100; count goes on to the end of the text.
  - `pattern` string: The regular expression, without slashes. Up to 4096 bytes.
  - `replace` string: Replace every match with this: $1, $<name>, $& and $$ in js; ${1}, ${name} and $$ in re2.
  - `text` string, required: The text to test the pattern on (pattern and options in the query), or JSON {"pattern": ..., "text": ...} with the options beside them.

## Response `200`

Success

- Envelope
  - `data` unknown, required
  - `meta` object, required
    - `limit` integer
    - `note` string
    - `offset` integer
    - `source` object: Where the data came from and the credit its licence asks for.
      - `attribution` string
      - `licence` string
      - `name` string
      - `retrieved` string
      - `url` string
      - `version` string
    - `total` integer

## Other responses

- `400`: Error
- `404`: Error
- `429`: Error

---

[API](https://skmtc.dev/dharun/apis/india-api-free-open-source-apis-for-indian-data.md) · [All operations](https://skmtc.dev/dharun/apis/india-api-free-open-source-apis-for-indian-data/llms.txt) · [OpenAPI document](https://skmtc.dev/dharun/apis/india-api-free-open-source-apis-for-indian-data/revisions/ecd8b0ec7863?raw)
