Python最新答案
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 = '\n'.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 = '\n'.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 = '\n'.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]+\b') word_list = re.findall(regular,str) word_str = '\n'.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://\b|/[a-z0-9.?=/_&]+\b') domain_name = re.sub(regular,"",str) domain_str = "".join(domain_name) print(domain_str)
爱我没结果!