CFLib.org – Common Function Library Project

getEmails(str)

Last updated June 13, 2011

author

Raymond Camden

Version: 3 | Requires: CF5 | Library: StrLib

Description:
This UDF will search a string for email addresses and return the matches as a list.

Return Values:
Returns a list.

Example:

<cfset emailList = "Gerardo Trevi?o Rojas gtrevino@metro.com.mx,Guillermo Dewey <gdewey@metro.com.mx>,Ma Luisa <luisa@metro.com.mx>;sales'<info@kompressorserver.com>'">
<cfoutput>#getEmails(emailList)#</cfoutput>

Parameters:

Name Description Required
str String to search. Yes

Full UDF Source:

/**
 * Searches a string for email addresses.
 * Based on the idea by Gerardo Rojas and the isEmail UDF by Jeff Guillaume.
 * New TLDs  
 * v3 fix by Jorge Asch
 * 
 * @param str      String to search. (Required)
 * @return Returns a list. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 3, June 13, 2011 
 */
function getEmails(str) {
    var email = "(['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.((aero|coop|info|museum|name|jobs|travel)|([a-z]{2,3})))";
    var res = "";
    var marker = 1;
    var matches = "";
    
    matches = reFindNoCase(email,str,marker,marker);

    while(matches.len[1] gt 0) {
        res = listAppend(res,mid(str,matches.pos[1],matches.len[1]));
        marker = matches.pos[1] + matches.len[1];
        matches = reFindNoCase(email,str,marker,marker);        
    }
    return res;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson