pyparsing / pyparsing

Python library for creating PEG parsers
MIT License
2.15k stars 276 forks source link

Example request: email parsing #539

Closed johnwbyrd closed 4 months ago

johnwbyrd commented 5 months ago

Great library, love its design.

I looked through the examples folder, but I did not see one particular use case for pyparsing that struck me as a natural demonstration case. In particular, https://www.rfc-editor.org/rfc/rfc822 and https://datatracker.ietf.org/doc/html/rfc5322 specify a fairly gnarly looking regex for email address validation.

It strikes me that, while a lot of people could write such a validator using pyparsing, perhaps the author/authors of pyparsing would prefer to write an email address parser that (1) works consistent to RFC 5322 and (2) observes pyparsing "best practices."

Thanks for your kind consideration.

ptmcg commented 5 months ago

I looked at RFC5322 today, and from picking through the doc, I think I have a working regex that is not overly unwieldy (certainly no worse than the current IPv6 parser). I think I'll eventually put it in pyparsing.common so that it is easier to incorporate into applications, but leaving it in examples for now will make it easier for me to take feedback on the regex accuracy.

Thanks for the suggestion!

ptmcg commented 4 months ago

Released in the examples in 3.1.2