# Regex tester

> Test a JavaScript pattern, read the groups, and preview a replacement.

Free JavaScript regex tester. Set flags, see every match and capture group, read a short explanation of the pattern, and preview a replacement. The match list is exact, which is what an agent needs when a model guesses.

- Page: https://benchline.fabwaseem.com/t/regex-tester
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: A JavaScript pattern, flags, a sample, and an optional replacement.
- Output: Matches with indexes and groups, a short explanation, and the replaced sample.
- Keywords: regex tester, javascript regex, regex replace
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Enter a pattern.** Type the pattern without slashes. Turn on the flags you need.
2. **Paste a sample.** Matches are marked in the sample. Each row lists the index and the groups.
3. **Preview a replacement.** Leave the replacement empty to skip it. $1 and $<name> work as they do in JavaScript.

## Use it from an AI agent

MCP tool name: `test_regex`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/regex-tester with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Run a JavaScript regular expression against a sample and return every match, capture group, a short explanation, and an optional replacement.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "pattern": {
      "type": "string",
      "description": "JavaScript regular expression body, without slashes."
    },
    "flags": {
      "default": "",
      "type": "string"
    },
    "text": {
      "type": "string",
      "description": "Sample to search."
    },
    "replacement": {
      "description": "When set, the sample is replaced and returned.",
      "type": "string"
    }
  },
  "required": [
    "pattern",
    "flags",
    "text"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "test_regex",
    "arguments": {
      "pattern": "example",
      "flags": "",
      "text": "example"
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### Which engine is this?

JavaScript RegExp, the same engine this page runs in. It is not PCRE. A pattern that works here works in a browser and in Node.

### Does the global flag change the match list?

The match list always searches the whole sample. The replacement preview adds the global flag when it is missing, so every match is replaced.

### Why might a pattern stall?

Some nested quantifiers make JavaScript backtrack for a long time. Samples are capped at 50,000 characters and the match list stops at 500.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [SQL formatter](https://benchline.fabwaseem.com/t/sql-formatter): Format SQL for PostgreSQL, MySQL, BigQuery, Snowflake, and other dialects.
- [Base64 codec](https://benchline.fabwaseem.com/t/base64-codec): Encode and decode Base64 for text or a file, including the URL-safe alphabet.
- [Cron expression builder](https://benchline.fabwaseem.com/t/cron-expression-builder): Build or paste a cron schedule, read it in plain English, and see the next run times.
