python 正则表达式提取
PHP中文网
PHP中文网 2017-04-18 10:25:33
0
1
528
41. gnos, gnit, gniz [L, GK]= to know 知

李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3397-3398). 外语教学与研究出版社. Kindle 版本.

42. grad, gress [L]= to step 步

李平武. 英语词根与单词的说文解字(修订版) (Kindle 位置 3448-3449). 外语教学与研究出版社. Kindle 版本.

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

谢谢!

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
PHPzhong
import re

regex = r"^\d.*"

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

matches = re.finditer(regex, test_str, re.MULTILINE)

for match in matches:

    
    print (match.group())
    
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!