python正则表达式count和prin

2024-04-25 11:50:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下文件文本。text:- 你知道吗

2013年6月8日05:04:02
2013年6月8日05:04:02
2013年6月8日05:04:02
2013年6月8日05:04:03
2013年6月8日05:04:03
2013年6月8日05:05:23
2013年6月8日05:05:23
2013年6月8日05:05:23
2013年6月8日05:05:23

我想用p打印这样的东西ython:- 你知道吗

2013年6月8日05:04:02-----3
2013年6月8日05:04:03----------2
2013年6月8日05:05:23----------4

这是我做的,我是这里的新手:-

"
import re
pattern = re.compile("\d+-\w+-\d+\s\d+:\d+:\d+")
open_file=open('mytest.txt')
for line in open_file:
four_letter_words = pattern.findall(line)
fp_len = len(pattern.findall(line))
for word in four_letter_words:
print four_letter_words , fp_len
"


Tags: 文件in文本reforlenlineopen

热门问题