Skip to content

Regex

Test whether a pattern matches, find all matches, or extract capture groups from text.

FieldTypeRequiredDescription
actionstringYestest, match, or extract
patternstringYesRegular expression pattern
inputstringYesText to match against
FieldTypeDescription
matchbooleanWhether the pattern matched
countintegerNumber of matches found
matchesarrayMatch details (when action is match or extract)
matches[].textstringMatched text
matches[].startintegerStart index
matches[].endintegerEnd index
matches[].groupsarrayCapture group values
Terminal window
curl -X POST https://morso.dev/api/regex \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"action": "test", "pattern": "^[a-z]+@[a-z]+\\.[a-z]+$", "input": "[email protected]"}'
{
"match": true,
"count": 1
}
Terminal window
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"]
}
]
}
  • 400 — Invalid regular expression pattern.

See Errors for the standard error shape.