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
| Field | Type | Required | Description |
|---|---|---|---|
text | string | required | The input text to search through. |
pattern | string | required | The search pattern — either a literal string or a regular expression. |
mode | "exact" | "regex" | required | Whether the pattern is a literal string or a regex. |
position | "contains" | "prefix" | "suffix" | "exact" | required | Match position for exact mode: contains, prefix, suffix, or exact match. |
caseInsensitive | boolean | required | Ignore letter case when matching. |
wholeWord | boolean | required | Match complete words only, not substrings. |
invertMatch | boolean | required | Return non-matching lines instead of matching lines. |
keepBlankLines | boolean | required | Preserve empty lines in results. |
maxHits | number | required | Maximum number of match results to return. |
linesBefore | number | required | Number of context lines before each match. |
linesAfter | number | required | Number of context lines after each match. |
trimWhitespace | boolean | required | Remove leading/trailing whitespace from lines. |
flags | object | required | Regex flags (only used in regex mode). |
Response
| Field | Type | Required | Description |
|---|---|---|---|
matches | object[] | required | Matched lines with highlight ranges. |
totalLines | number | required | Total number of lines in input. |
matchCount | number | required | Number of matched lines. |
nonMatchCount | number | required | Number 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.