我有话
我创建基于词处理“++”在Python正则表达式标志
import re
word = 'This is word of spy++'
wl = ['spy++','cry','fpp']
regobjs = [re.compile(r"\b%s\b" % word.lower()) for word in wl]
for reobj in regobjs:
print re.search(regobj, word).group()
但是在建立正则表达式我得到错误(error: multiple repeat)
这个名单上的正则表达式对象的列表清单objs,因为符号++ 我如何使正则表达式来处理单词列表中的所有单词的情况?
requirements:
regex should detect the exact word from the given text
even if the word having non alpha numeric chars like (++) above code detect the exact words except those having ++ char.
你需要['re.escape()'](HTTP://docs.python .ORG /库/ re.html#re.escape)。 –
@SvenMarnach:他需要比这更多的... –
@Sashi没有人想要获得错误。想要“不要获得”并不会带来关于“获得”的信息。写作_“处理所有情况”_超级模糊 – eyquem