Write a regular expression to match emails. Complete email formats can be complex but your expression should accept at least the following format examples. john_doe@hotmail.com my-email-81@mydomain.co.nz firstname.lastname@email.com.au
时间: 2024-03-29 14:40:04 浏览: 74
Sure, here's a regular expression that will match most common email formats:
```
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
```
This regular expression matches the following components:
- `\b` matches a word boundary (a space or punctuation mark)
- `[A-Za-z0-9._%+-]+` matches one or more letters, digits, dots, underscores, percent signs, plus signs or hyphens in the username
- `@` matches the at symbol
- `[A-Za-z0-9.-]+` matches one or more letters, digits, dots or hyphens in the domain name
- `\.` matches a period (escaped with a backslash)
- `[A-Z|a-z]{2,}` matches two or more letters (upper or lowercase) in the top-level domain
- `\b` matches another word boundary
This regular expression should match the email formats you provided as examples.
阅读全文