Skip to content

Conversation

Richienb
Copy link
Contributor

@Richienb Richienb commented Jul 15, 2025

The perfect email regex

It turns out that the parts of rfc 5322 responsible for defining what an email is, can be cross-compiled 1:1 to regex. At some point I will publish this abnf to regex converter (update: published at https://github.com/Richienb/abnf-regex). (I am also waiting for this PR which would improve the optimisation phase DmitrySoshnikov/regexp-tree#269)

TODO:

Fixes #9, fixes #2, fixes #15

@Richienb
Copy link
Contributor Author

Richienb commented Jul 19, 2025

Should hopefully be non-breaking
If it were breaking, maybe also disallow &amp by default, which would be my preference. It would also make it RFC 5322 compliant.

@Richienb
Copy link
Contributor Author

Added TypeScript devdep to make tests pass
Won't be needed in later versions of xo that support newer versions of Node

@Richienb Richienb marked this pull request as ready for review July 19, 2025 13:28
@Richienb Richienb changed the title Make regex RFC 5322-compliant Return RFC 5322-compliant regex Jul 19, 2025
@Richienb
Copy link
Contributor Author

Regex is now quite large
Could be fixed by adding options that disable other features

@Richienb Richienb changed the title Return RFC 5322-compliant regex Use RFC 5322-compliant regex Jul 19, 2025
@sindresorhus
Copy link
Owner

If it were breaking, maybe also disallow &amp by default, which would be my preference. It would also make it RFC 5322 compliant.

Yeah, let's disable that by default. I will do a major version anyway.

@Richienb Richienb changed the title Use RFC 5322-compliant regex Become RFC 5322-compliant Jul 20, 2025
@Richienb Richienb requested a review from sindresorhus July 20, 2025 12:05
@sindresorhus sindresorhus merged commit 39392e6 into sindresorhus:main Aug 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to allow &amp; Noticing some odd matches This string passes as an exact match: '<[email protected]>'
2 participants