Regular expressions are powerful and notoriously hard to write correctly. Here's how to test, explain, and generate regex patterns via API β without memorizing syntax.
The Three Problems with Regex
Writing : Syntax differs between languages. JavaScript, Python, and Go have subtle incompatibilities.
Testing : You need sample data to verify edge cases.
Reading : Six months later, /^(?:[a-z0-9!#$%&'*+/=?^_ {|}~-]+(?:.[a-z0-9!#$%&' +/=?^_{|}~-]+) )/` means nothing.
Pattern Testing via API
`python
import requests
Test a regex against multiple strings at once
resp = requests.post(" https://api.lazy-mac.com/regex-toolkit/test ", json={
"pattern": r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$",
"flags": "i",
"test_cases": [
" [email protected] ",
" [email protected] ",
"not-an-email",
"missing@tld",
"@nodomain.com"
]
})
for result in resp.json()['results']:
print(f"{'β
' if result['match'] else 'β'} {result['input']}")
`
Output:
plaintext
β
[email protected]
β
β¦