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

Re: st: Dropping not valid emails

From   Phil Schumm <>
Subject   Re: st: Dropping not valid emails
Date   Tue, 19 Feb 2008 05:53:17 -0600

On Feb 19, 2008, at 5:10 AM, 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:


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

-- Phil

* For searches and help try:

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