Skip to main content
Inspiring
March 17, 2010
Answered

Trimming a string using spaces as a delimitter

  • March 17, 2010
  • 1 reply
  • 532 views

I'm trying to retreive email addresses from individual message bodies. I'm using the following code and it is working well :

<cfset addrpos = ListContainsNoCase(getmail.body, "@", " <> ")>
     <cfif addrpos neq 0>
     <cfset email = ListGetAt(getmail.body, addrpos, " <> ")>

     </cfif>

For the most part this is working well, but at times the <> characters  are not surrounding the email address in the message bodyand I'm ending up with the email address and a combination of the word before, word after or both. Is there a better way to handle this situation? I tried the following which works when I set the email variable in the example, but does not work when I use the same code in the loop that is getting the original email variable.

<cfset email = "adfga: chunt@example.com adfw asdfa">
<cfset addrpos1 = ListContainsNoCase(email, "@", " ")>
<cfset EMAIL = ListGetAt(email, addrpos1, " ")>

I looked at the GetToken function but did not think that it would be a better way to go at it. Any other ideas?

    This topic has been closed for replies.
    Correct answer Fernis

    Finding email addresses in a bunch of text without using regular expressions? Mad, I say, Mad!

    Hints:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e9a.html

    Try using regular expression to match any valid email:

    [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}

    Allow returnsubexpressions on ReFind to return multiple hits on the message body.

    Use cfdump to check how you must access the result array.

    Hope this helps.

    --

    - Fernis - fernis.net - ColdFusion Developer For Hire

    1 reply

    Fernis
    FernisCorrect answer
    Inspiring
    March 17, 2010

    Finding email addresses in a bunch of text without using regular expressions? Mad, I say, Mad!

    Hints:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e9a.html

    Try using regular expression to match any valid email:

    [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}

    Allow returnsubexpressions on ReFind to return multiple hits on the message body.

    Use cfdump to check how you must access the result array.

    Hope this helps.

    --

    - Fernis - fernis.net - ColdFusion Developer For Hire

    Inspiring
    March 17, 2010

    Thanks Fernis, that worked well.