I have text strings that I need to extract the email addresses from. The strings look something like this
“Natalia ferrara 077559 020 8946 66003 byrens singnatxxx@hotmail.com”
The will always be a space or two either side of the address but the address could be in any postion in the string
I know some of you chaps are brillant at this text manipulation stuff so any help would be appreciated
Quick & Dirty
set txt to {"Natalia ferrara 077559 020 8946 66003 byrens singnatxxx@hotmail.com", "Fan Boy maxnatxxx@hotmail.com 077559 020 8946 66003 byrens "}
set AddressList to {}
repeat with i from 1 to number of items in txt
set this_txt to item i of txt
set wrd to words of this_txt as list
set counter to 0
repeat with i from 1 to number of items in wrd
set counter to counter + 1
set this_item to item i of wrd
if this_item is equal to "@" then
copy item (counter - 1) of wrd & this_item & item (counter + 1) of wrd as string to end of AddressList
end if
end repeat
end repeat
AddressList
Thats ok, there a probably many way to do it.
Slightly cleaner
set txt to {"Natalia ferrara 077559 020 8946 66003 byrens singnatxxx@hotmail.com", "Fan Boy maxnatxxx@hotmail.com 077559 020 8946 66003 byrens "}
set AddressList to {}
repeat with i from 1 to number of items in txt
set AppleScript's text item delimiters to {"@"} --sets new dilm
set this_txt to item i of txt
set right_txt to word 1 of text item -1 of this_txt
set left_txt to word -1 of text item 1 of this_txt
set AppleScript's text item delimiters to "" -- resets dilm
copy left_txt & "@" & right_txt as string to end of AddressList
end repeat
AddressList
edit…Oops had my right/left _txt in wrong place, fixed