使用正则表达式提取文本

5年以前  |  阅读数:455 次  |  编程语言:Python 
import re
#用(?P<year>...)括住一个群,并命名为year
m = re.search("output_(?P<year>\d{4})", "output_1986.txt")
print(m.group("year") #输出1986

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8