Professional Software Development for FileMaker®

FileMaker Business Alliance
FileMaker 8 Certified Developer
FileMaker 10 Certified Developer
SUI Solutions is an independent entity and this web site has not been authorized, sponsored, or otherwise approved by FileMaker, Inc.

New to FileMaker?

FileMaker 11

Learn about the most
incredible database now!

ExtractEmails

Filemaker custom function that extracts list of e-mails found in Text.

Format

ExtractEmails ( Text )

Parameter

Text - source text with e-mails

Data type returned

text

Description

Extracts from Text the list of all e-mails separated by carriage returns.

Example

Input:

ExtractEmails("^john_smith@mails.com; and some other email; example@suisolutions.com? and one more please##bill.smith@email.com,,custom@function.net,")

Output (list of extracted e-mails):

john_smith@mails.com
example@suisolutions.com
bill.smith@email.com
custom@function.net

Source code

Select all
Let([ adjustedText = If( $Already_Sub="yes";Text; Substitute ( text ; "¶" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; ";" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "," ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "<" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; ">" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "!" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "\\" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "\"" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "#" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "$" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "%" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "&" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "'" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "*" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "/" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; ":" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "?" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "[" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "]" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "^" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "{" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "}" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "|" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "~" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "`" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; "(" ; " " )); adjustedText = If( $Already_Sub="yes";adjustedText; Substitute ( adjustedText ; ")" ; " " )); $Result = If( $Already_Sub="yes";$Result; "¶"); $Already_Sub = "yes"; len = Length ( adjustedText ); pos = Position ( adjustedText ; "@" ; 1 ; 1 ); startWord = Position ( adjustedText ; " " ; pos ; -1 ) + 1; endWord = If ( Position ( adjustedText ; " " ; pos ; 1 ) ≠ 0 ; Position ( adjustedText ; " " ; pos ; 1 ) ; len + 1 ); email = Middle ( adjustedText ; startWord ; endWord - startWord ); $Result =If( PatternCount (email;"@" ) = 1 and Position ( email ; "@"; 1 ; 1 ) > 1 and Position ( email ; "."; 1 ; 1 ) > 1 and Position( email; ".."; 1 ; 1 ) = 0 and Position ( email ; "."; Length ( email ) ; -1 ) > Position ( email ; "@" ; 1 ; 1 ) + 1 and Position ( email ; "."; Length ( email ) ; -1 ) ≤ Length ( email ) - 2 and PatternCount ($Result; "¶" & email & "¶") = 0 and Position ( email ; "."; Length ( email ) ; -1 ) < Length ( email ); $Result&email&¶; $Result); adjustedText = Replace ( adjustedText ; startWord; Length ( email ) ; "" ); count = PatternCount ( adjustedText ; "@" ) ]; If(count ≠ 0; ExtractEmails(adjustedText);Middle($Result; 2; Length ($Result )-2)))