Regex
Test whether a pattern matches, find all matches, or extract capture groups from text.
POST /api/regex
Section titled “POST /api/regex”Parameters
Section titled “Parameters”| Field | Type | Required | Description |
|---|---|---|---|
action | string | Yes | test, match, or extract |
pattern | string | Yes | Regular expression pattern |
input | string | Yes | Text to match against |
Response
Section titled “Response”| Field | Type | Description |
|---|---|---|
match | boolean | Whether the pattern matched |
count | integer | Number of matches found |
matches | array | Match details (when action is match or extract) |
matches[].text | string | Matched text |
matches[].start | integer | Start index |
matches[].end | integer | End index |
matches[].groups | array | Capture group values |
Examples
Section titled “Examples”Test a pattern
Section titled “Test a pattern”curl -X POST https://morso.dev/api/regex \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \{ "match": true, "count": 1}Extract matches
Section titled “Extract matches”curl -X POST https://morso.dev/api/regex \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"action": "extract", "pattern": "(\\d{4})-(\\d{2})-(\\d{2})", "input": "Born on 1990-05-15, graduated 2012-06-01"}'{ "match": true, "count": 2, "matches": [ { "text": "1990-05-15", "start": 8, "end": 18, "groups": ["1990", "05", "15"] }, { "text": "2012-06-01", "start": 30, "end": 40, "groups": ["2012", "06", "01"] } ]}Errors
Section titled “Errors”- 400 — Invalid regular expression pattern.
See Errors for the standard error shape.