您的位置:首页技术文章
文章详情页

python 正则表达式提取

浏览:91日期:2022-08-31 10:45:03

问题描述

41. gnos, gnit, gniz [L, GK]= to know 知李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3397-3398). 外语教学与研究出版社. Kindle 版本.42. grad, gress [L]= to step 步李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3448-3449). 外语教学与研究出版社. Kindle 版本.

有如上内容,怎么样才可以通过正则表达式仅抓取数字那一行的内容,而忽略掉关于来源的内容呢?

谢谢!

问题解答

回答1:

import reregex = r'^d.*'test_str = ('41. gnos, gnit, gniz [L, GK]= to know 知nn' '李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3397-3398). 外语教学与研究出版社. Kindle 版本.nn' '42. grad, gress [L]= to step 步nn' '李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3448-3449). 外语教学与研究出版社. Kindle 版本.')matches = re.finditer(regex, test_str, re.MULTILINE)for match in matches:print (match.group())

标签: Python 编程
相关文章: