Globalz
Globalz

Reputation: 4604

Regex clean up list of unformatted emails addressess

Hi Recently had a list of email addresses in a poorly formatted csv file with things like: [email protected]; [email protected]; [email protected]; Email-Name; [email protected]; Another Name; First Name([email protected]);

How would I remove the illegitimate emails? I think if I could match each line that didnt contain an @symbol would have been pretty helpful

Upvotes: 1

Views: 1562

Answers (1)

nss
nss

Reputation: 561

The following regex should match all lines that don't contain an @ symbol:

^[^@]*$

The first ^ matches the beginning of a line, the brackets indicate a character class. The second caret means "this class matches any character except the following..." The @ is the character we wish to disallow. The * means "any number of characters that match the character class" and the $ matches the end of the line.

Sorry if this is overly pedantic. :)

You should note that actually matching valid emails is considerably more complex and somewhat open to interpretation: http://www.regular-expressions.info/email.html

Upvotes: 2

Related Questions