Sometimes you need to pull just the email addresses out of mixed text โ an email body, or text transcribed from a business card image.
The basic email pattern
A pattern roughly like [\w.+-]+@[\w-]+\.[\w.-]+ catches most emails. The fully correct RFC 5322 email grammar is far more complex, but this practical pattern is enough for real-world use.
A common false positive โ trailing punctuation
In a sentence like "my email is [email protected]. Thanks," the trailing period after the sentence often gets swept up into the extracted email. Stripping a trailing period off the domain part is a common post-processing step.
Deduplication and case
The standard technically treats the local part (before the @) as case-sensitive, but in practice nearly every mail server treats it as case-insensitive. Normalizing to lowercase before deduping is the usual approach.