Regex to find all email addresses in text

Use /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g to find every match in a text. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g
Open in Regex Tester

Sample text

Contact sales@example.com or support@devpack.app. Jane (jane.doe+news@mail.example.co.uk) replied; ignore @handles and user@localhost.

3 matches

sales@example.com support@devpack.app jane.doe+news@mail.example.co.uk

How the pattern works

PartMeaning
[A-Za-z0-9._%+-]+The local part
@The @ sign
[A-Za-z0-9.-]+\.[A-Za-z]{2,}The domain and top-level domain
g flagFind every match, not just the first

Code examples

JavaScript

const matches = text.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g) ?? [];

Python

import re

matches = re.findall(r'[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}', text)

PHP

preg_match_all('/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/', $text, $m);
$matches = $m[0];

Notes and limitations

Without the ^ and $ anchors the pattern finds addresses anywhere in a text. Paste a whole document into the Regex Tester to list every match.

Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool

Frequently asked questions

What is the regex to find all email addresses in text?
/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g — it finds every match in a text. See the table above for what each part does.
Does it work in Python and PHP?
Yes — the code examples above use the same pattern with re in Python and preg functions in PHP.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.