import re # 文本 telNumber = '''Suppose my Phone No. is 0535-1234567, yours is 010-12345678, his is 025-87654321. ''' # 正则表达式模式 regular = re.compile(r'd+-d+') tel_list = re.findall(regular,telNumber) tel_str = ' '.join(tel_list) print(tel_str) str= ''' dgned@123.com sdfadf@.com efddfd124@180.com df2dhtd@123.com dflfdfi@139.com feffzd.com defgdf@.sodf.com.com ''' regular = re.compile(r'w*d*[@]w+.com|w*d*[@]d+.com') email_list = re.findall(regular,str) email_str = ' '.join(email_list) print(email_str) str='aldb153 2019-03-26 14:30:00 2019-03-12 09:30:10' regular = re.compile(r'd{4}[-]d{2}[-]d{2} d{2}[:]d{2}[:]d{2}') date_list = re.findall(regular,str) date_str = ' '.join(date_list) print(date_str) str='The shortest way 124 to do many 23111 things is to do 1689 only one thing 246 at a time' regular = re.compile(r'[a-zA-Z]+') word_list = re.findall(regular,str) word_str = ' '.join(word_list) print(word_str) str = '''http://www.interoem.com/messageinfo.asp?id=35 http://3995503.com/class/class09/news_show.asp?id=14 http://lib.wzmc.edu.cn/news/onews.asp?id=769 http://www.zy-ls.com/alfx.asp?newsid=377&id=6 http://www.fincm.com/newslist.asp?id=415''' regular = re.compile(r'http://|/[a-z0-9.?=/_&]+') domain_name = re.sub(regular,"",str) domain_str = "".join(domain_name) print(domain_str)