Parsing “From” addresses from email text

前端 未结 8 2136
春和景丽
春和景丽 2021-02-19 03:56

I\'m trying to extract email addresses from plain text transcripts of emails. I\'ve cobbled together a bit of code to find the addresses themselves, but I don\'t know how to mak

8条回答
  •  滥情空心
    2021-02-19 04:50

    "[stuff]@[stuff][stuff1-4 letters]" is about right, but if you wanted to you could decode the regular expression using a trick I just found out about, here. Do the compile() in an interactive Python session like this:

    mailsrch = re.compile(r'[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}', 128)
    

    It will print out the following:

    in 
      category category_word
      literal 45
    max_repeat 1 65535 
      in 
        category category_word
        literal 45
        literal 46
    literal 64 
    in 
      category category_word
      literal 45
    max_repeat 1 65535 
      in 
        category category_word
        literal 45
        literal 46
    max_repeat 1 4 
      in 
        range (97, 122)
        range (65, 90)
    

    Which, if you can kind of get used to it, shows you exactly how the RE works.

提交回复
热议问题