Regexr email
Here is a regular expression that matches most common email address formats:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Let me break it down:
^
matches the start of the string[a-zA-Z0-9._%+-]+
matches one or more of the following characters:- Letters (both uppercase and lowercase)
- Numbers
- Dot (.)
- Hyphen (-)
- Underscore (_)
- Percent (%)
- Plus sign (+)
@
matches the @ symbol[a-zA-Z0-9.-]+
matches one or more of the following characters:- Letters (both uppercase and lowercase)
- Numbers
- Dot (.)
- Hyphen (-)
\.
matches a period (.) character[a-zA-Z]{2,}
matches the domain extension (it must be at least 2 characters long and only contain letters)$
matches the end of the string
This regular expression should match most common email address formats, but keep in mind that it's not foolproof. Some email addresses may not match this pattern, and some valid email addresses may match this pattern but not be valid according to the email specification.
Here are some examples of email addresses that this regular expression would match:
And here are some examples of email addresses that this regular expression would not match:
- @example.com (missing local part)
- example..com (multiple dots in a row)
- [email protected] (missing domain)
- [email protected] (numbers only in the local part)
Keep in mind that this is just one example of a regular expression that matches email addresses, and there are many other ways to write a regular expression that matches email addresses.