Utilo

Email Regular Expression – Free, Online, Private

A practical email pattern for finding addresses in text, not a full RFC 5322 parser.

Tester
Sample
Matches (2)
  • ada@example.com
  • grace.hopper@navy.mil

The pattern

The pattern matches a local part, an @, a domain, a dot, and a letter-only ending of at least two characters. It is the check people put on a form when they want to reject an empty string and a string with a space, and then confirm the address by sending mail. It will match ada@example.com and grace.hopper@navy.mil in the sample. It will not match ada@localhost, because there is no dot in the domain, and it will not match a sentence that wrote the @ as a word.

The source is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. No flags are set. The match is case-sensitive, and ^ or $ mean the start and end of the whole input. Add m yourself in the tester if you paste several lines. The box under the title is a tester with this pattern and the sample already filled in. Edit either one. Nothing you type is uploaded. The same tester, without a preset, is the regex tool.

How to read it

The first character class is the local part: letters, digits, dot, underscore, percent, plus, and hyphen, one or more times. The plus on the end of the class is the quantifier, not a plus sign in the address, though a literal plus is also allowed inside the class. Then a literal @. The domain class allows letters, digits, dots, and hyphens. The trailing \.[a-zA-Z]{2,} requires a dot and at least two letters, which is why .com matches and a trailing dot does not. There is no ^ and no $, so the pattern finds an address inside a sentence. Add anchors when you are validating a whole field.

What it will not do

This is not RFC 5322. Quoted local parts, comments, and IP-address domains are out of scope. It allows a leading dot and a double dot, which real mail servers often reject. It allows a domain label to start with a hyphen. Internationalized domains have to be punycode before this pattern will see them as ASCII. The point of publishing the pattern is to show a version you can explain, and to show the tester rejecting the two non-addresses in the sample. Do not use it as the only proof that mail will be delivered.

A match is not a parsed value. An email pattern does not send mail, a UUID pattern does not allocate an id, and a password pattern does not store a password. When the next step needs a real parser, use one: the URL constructor, a date library, a semver library, or the converters on this site. The expression is the part you can see.

JavaScript, Python, and Go

The JavaScript snippet uses the RegExp constructor so the source does not have to be escaped for a literal slash. The Python snippet uses a normal string with the same escapes JSON would emit, which keeps \d as a regex digit class. Go's snippet uses a raw string. If the pattern contains a lookahead, the Go snippet says so and does not call MustCompile, because RE2 would reject it at runtime.

JavaScriptconst re = new RegExp("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}", "");
const found = text.match(re);
console.log(found ? found[0] : "no match");
Pythonimport re

pattern = re.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}")
found = pattern.search(text)
print(found.group(0) if found else "no match")
Gopackage main

import (
	"fmt"
	"regexp"
)

func main() {
	text := ""
	re := regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`)
	fmt.Println(re.FindString(text))
}

Frequently asked questions

Does this accept every legal email address?

No. It accepts the common ASCII shape and rejects addresses a real server might still deliver, including ones without a dot in the domain.

Why is there no anchor?

So the tester can find an address inside a sentence. Anchor with ^ and $ when the whole input must be one address.

Will it match uppercase?

Yes. The classes include A-Z and a-z. A flag is not required for that.

Should I use this to block signups?

Use it to catch typos, then send a confirmation message. Delivery is the real check.