python 中的问题 关于re模块

2025-02-27 03:24:42
推荐回答(3个)
回答1:

import re
str10 = "The quick brown fox jumps over the lazy dog."
str10_list = str10.split()
pattern = re.compile(r"(?PThe)",re.I)#/
print("output #39:")
for word in str10_list:
    if pattern.search(word):
        print("{:s}".format(pattern.search(word).group('match_word')))

这样就对了


回答2:

pattern = re.compile(R"(?PThe)",re.I)
这部分本身的正则就写错了
这里的是什么?另外中间的,也会报错。

回答3:

正则表达式有问题。把 删掉。