back

by LinuxBender·10y ago·view on hn ↗

    # get email addresses
    grep -EiEio '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'

    # censor email addresses
    sed -r 's/(<)[[:alpha:][:digit:]\._%\+-]+@[[:alpha:][:digit:]\.-]+\.[[:alpha:]]{2,4}(>)/\1--removed--\2/g'
If email doesn't meet those, I drop them on the floor. Then again, I drop email on the floor for lesser reasons.
3 comments
So you're blocking email from your local .museum, from anyone who has an Irish name like O'Connor, all international TLDs, and most newer TLDs.
Yes.
So any new gtld longer than four characters would be dropped on the floor? E.g. .software? If you're trying to censor email addresses from a file, that doesn't work that well. :)
Yes. Actually for the longest time I rejected the connection with "Your name is too awesome!"
This would not allow email addresses with an = in them, which I've had. The point of my overly tolerant regex is exactly that: any more restrictive validation is going to drop some perfectly legal email addresses. Sending an email is the only way to be sure.