Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Dropping not valid emails


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Dropping not valid emails
Date   Tue, 19 Feb 2008 05:53:17 -0600

On Feb 19, 2008, at 5:10 AM, Alexander.Severinsen@telenor.com wrote:
I have a variable that contains e-mail adresses. I would like to find a way to drop observations that does not contain valid email adresses. There should be a condition that the string contains one '@', the exsistence of period, and two or three characters following the period, and no empty spaces.

This is best handled with a regular expression (i.e., with the -regexm ()- function). For example, the following regular expression will match most valid email addresses:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z][a-zA-Z][a-zA-Z]?[a- zA-Z]?$

Unfortunately, Stata's lack of support for curly braces (used to indicate bounds) means that you cannot use the following, shorter expression:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$

which is essentially the same as the one above. But the first one will work fine with -regexm()-.


-- Phil

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index