Regex Pattern to Match Email Addresses
• CronOS Team
regexemailvalidationtutorialbeginners
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!
Regex Pattern to Match Email Addresses
A simple explanation of the email regex pattern ^[\w\.-]+@[\w\.-]+\.\w+$ and how it works.
Pattern Breakdown
regex
^[\w\.-]+@[\w\.-]+\.\w+$
Components
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
[\w\.-]+ | Local part | One or more: word chars, dots, hyphens |
@ | Separator | Literal @ symbol |
[\w\.-]+ | Domain name | One or more: word chars, dots, hyphens |
\. | TLD separator | Literal dot (escaped) |
\w+ | TLD | One or more word characters |
$ | End anchor | Ensures match to string end |
Character Classes
\w- Word characters:[a-zA-Z0-9_]\.- Literal dot (escaped, since.matches any char)-- Literal hyphen+- Quantifier: one or more occurrences
Examples
Valid:
user@example.comjohn.doe@company.orgtest_email@sub.domain.comuser-123@domain-name.net
Invalid:
user@domain(missing TLD)@domain.com(missing local part)user@.com(missing domain)user name@domain.com(space not allowed)user@domain..com(double dot)user@domain.co.uk(multi-part TLD not supported)
Implementation
JavaScript
javascript
const emailRegex = /^[\w\.-]+@[\w\.-]+\.\w+$/;
emailRegex.test('user@example.com'); // true
Python
python
import re
email_regex = r'^[\w\.-]+@[\w\.-]+\.\w+$'
bool(re.match(email_regex, 'user@example.com')) # True
Go
go
emailRegex := regexp.MustCompile(`^[\w\.-]+@[\w\.-]+\.\w+$`)
emailRegex.MatchString("user@example.com") // true
Limitations
- Multi-part TLDs: Doesn't match
.co.uk,.com.au - No length validation: RFC 5322 limit is 320 characters
- No quoted strings: Doesn't support
"user name"@example.com - No plus signs: Doesn't allow
+in local part
When to Use
- Client-side form validation
- Basic format checking
- Quick validation before API calls
For production, consider RFC 5322-compliant patterns or validation libraries, and always verify emails via confirmation messages.
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!