import Text.Regex
mail :: Regex
mail = mkRegex "(([a-zA-Z0-9]+[ \t]+)?[a-zA-Z0-9]+[ \t]+)?((mailto://)?[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+)"
mainmatch s = case m of {
Nothing -> [];
Just (pre, mm, post, sub) -> (sub!!0, sub!!2):mainmatch post
} where m = Text.Regex.matchRegexAll mail s
htmlformat s = "<ul>\n" ++ (concat $ map htmlformatitem s) ++ "</ul>"
htmlformatitem (name, mail) = if name == ""
then "<li>\n\n\t<a href=\"" ++ mail ++ "\">\n\t " ++ mail ++ "\n\t\t</a></li>\n"
else "<li>" ++ name ++ ", \n\t<a href=\"" ++ mail ++ "\">\n\t " ++ mail ++ "\n\t\t</a></li>\n"
main = do
s <- readFile "names"
let sout = htmlformat $ mainmatch s in
writeFile "names.html" sout