Extract email sub-strings from large document

前端 未结 11 2227
星月不相逢
星月不相逢 2020-11-28 06:54

I have a very large .txt file with hundreds of thousands of email addresses scattered throughout. They all take the format:

......
         


        
11条回答
  •  心在旅途
    2020-11-28 07:11

    You can also use the following to find all the email addresses in a text and print them in an array or each email on a separate line.

    import re
    line = "why people don't know what regex are? let me know asdfal2@als.com, Users1@gmail.de " \
           "Dariush@dasd-asasdsa.com.lo,Dariush.lastName@someDomain.com"
    match = re.findall(r'[\w\.-]+@[\w\.-]+', line)
    for i in match:
        print(i)
    

    If you want to add it to a list just print the "match"

    # this will print the list
        print(match)
    

提交回复
热议问题