Regex for Email and URL
Pragmatic patterns for the two most-validated inputs.
- email regex
- url regex
- validate email
- extract url
- domain regex
Regex for Email and URL
Pragmatic patterns for the two most-validated inputs.
Commands
| Command | What it does |
|---|---|
^[^\s@]+@[^\s@]+\.[^\s@]+$ | Pragmatic email check |
https?://[^\s/$.?#].[^\s]* | Rough URL finder |
(?<proto>https?)://(?<host>[^/]+) | URL parts via named groups |
\b[\w.-]+\.[a-z]{2,}\b | Domain-ish token |
Example
const email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
email.test('ada@example.com')
FAQ
Is there a perfect email regex?
No - the RFC is too broad; use the pragmatic check above, then verify with a confirmation email.
How do I fully validate URLs?
Regex for shape plus the URL constructor in code - the constructor rejects what patterns miss.
Частые вопросы
Is there a perfect email regex?
No - the RFC is too broad; use the pragmatic check above, then verify with a confirmation email.
How do I fully validate URLs?
Regex for shape plus the URL constructor in code - the constructor rejects what patterns miss.