Statalist


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

SV: st: Dropping not valid emails


From   <Alexander.Severinsen@telenor.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   SV: st: Dropping not valid emails
Date   Tue, 19 Feb 2008 13:13:38 +0100

Phil, that did the trick. Thanks a lot!

Best wishes,
Alexander

-----Opprinnelig melding-----
Fra: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] På vegne av Phil Schumm
Sendt: 19. februar 2008 12:53
Til: statalist@hsphsun2.harvard.edu
Emne: Re: st: Dropping not valid emails

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/

*
*   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