Grep Pattern Tester API

Test exact strings or regex patterns against any input text. Live filtering with match highlighting, context lines, and invert match. 100% client-side.

The Grep Pattern Tester is also available as a free REST API. Send a POST request with a JSON body to https://dot.tools/api/tools/grep — no authentication, no API key, CORS enabled. Successful calls return { "ok": true, "result": { … } }; failures return HTTP 400 or 422 with an error body.

Request body

FieldTypeRequiredDescription
textstringrequiredThe input text to search through.
patternstringrequiredThe search pattern — either a literal string or a regular expression.
mode"exact" | "regex"requiredWhether the pattern is a literal string or a regex.
position"contains" | "prefix" | "suffix" | "exact"requiredMatch position for exact mode: contains, prefix, suffix, or exact match.
caseInsensitivebooleanrequiredIgnore letter case when matching.
wholeWordbooleanrequiredMatch complete words only, not substrings.
invertMatchbooleanrequiredReturn non-matching lines instead of matching lines.
keepBlankLinesbooleanrequiredPreserve empty lines in results.
maxHitsnumberrequiredMaximum number of match results to return.
linesBeforenumberrequiredNumber of context lines before each match.
linesAfternumberrequiredNumber of context lines after each match.
trimWhitespacebooleanrequiredRemove leading/trailing whitespace from lines.
flagsobjectrequiredRegex flags (only used in regex mode).

Response

FieldTypeRequiredDescription
matchesobject[]requiredMatched lines with highlight ranges.
totalLinesnumberrequiredTotal number of lines in input.
matchCountnumberrequiredNumber of matched lines.
nonMatchCountnumberrequiredNumber of non-matched lines.

Example request

curl -X POST https://dot.tools/api/tools/grep \
  -H 'Content-Type: application/json' \
  -d '{
  "text": "[2024-01-15 08:23:01] INFO  Server started on port 8080\n[2024-01-15 08:23:02] INFO  Database connection established\n[2024-01-15 08:24:15] WARN  Request timeout on /api/users (3000ms)\n[2024-01-15 08:25:03] ERROR Failed to authenticate user: invalid token\n[2024-01-15 08:25:04] ERROR Database query failed: connection reset\n[2024-01-15 08:26:12] INFO  User login successful: user_id=4521\n[2024-01-15 08:27:45] WARN  High memory usage detected: 89.2%\n[2024-01-15 08:28:01] ERROR Critical: Disk space below 5% on /dev/sda1\n[2024-01-15 08:28:33] INFO  Cache cleared successfully\n[2024-01-15 08:29:55] ERROR Network unreachable: backup server 10.0.1.50\n[2024-01-15 08:30:12] INFO  Scheduled task completed: email_digest\n[2024-01-15 08:31:00] WARN  SSL certificate expires in 14 days\n[2024-01-15 08:32:22] ERROR Permission denied: /var/log/secure\n[2024-01-15 08:33:01] INFO  Health check passed\n[2024-01-15 08:34:45] ERROR Service unavailable: payment gateway timeout",
  "pattern": "ERROR",
  "mode": "exact",
  "position": "contains",
  "caseInsensitive": false,
  "wholeWord": false,
  "invertMatch": false,
  "keepBlankLines": false,
  "maxHits": 100,
  "linesBefore": 0,
  "linesAfter": 0,
  "trimWhitespace": false,
  "flags": {
    "global": true,
    "multiline": false,
    "dotall": false,
    "unicode": false
  }
}'

Sample response

{
  "ok": true,
  "result": {
    "matches": [
      {
        "line": 4,
        "text": "[2024-01-15 08:25:03] ERROR Failed to authenticate user: invalid token",
        "ranges": [
          [
            22,
            27
          ]
        ]
      },
      {
        "line": 5,
        "text": "[2024-01-15 08:25:04] ERROR Database query failed: connection reset",
        "ranges": [
          [
            22,
            27
          ]
        ]
      },
      {
        "line": 8,
        "text": "[2024-01-15 08:28:01] ERROR Critical: Disk space below 5% on /dev/sda1",
        "ranges": [
          [
            22,
            27
          ]
        ]
      },
      {
        "line": 10,
        "text": "[2024-01-15 08:29:55] ERROR Network unreachable: backup server 10.0.1.50",
        "ranges": [
          [
            22,
            27
          ]
        ]
      },
      {
        "line": 13,
        "text": "[2024-01-15 08:32:22] ERROR Permission denied: /var/log/secure",
        "ranges": [
          [
            22,
            27
          ]
        ]
      },
      {
        "line": 15,
        "text": "[2024-01-15 08:34:45] ERROR Service unavailable: payment gateway timeout",
        "ranges": [
          [
            22,
            27
          ]
        ]
      }
    ],
    "totalLines": 15,
    "matchCount": 6,
    "nonMatchCount": 9
  }
}

Use the free Grep Pattern Tester in your browser, read the Grep Pattern Tester guide, or import the full OpenAPI specification.