textfields="""Conjugation of suorittaa """
stry2= """Conjugation"""
stryc=re.compile(stry2, re.DOTALL)
print 'textfields=', textfields, ' stry2=', stry2
LtryM=re.search(stryc, textfields); print 'LtryM', LtryM
我在字符串“suorittaa的共轭”中找不到单词“Conjugation”。 最后我打印了一个单词和一个字符串。 似乎不是“变位”,而是印刷字“xxxConjugation”,其中xxx是奇怪的字符。在
我怎么能解决这个问题。我还试着把这两个字符串都编码成“utf-8”。结果是一样的。 这些奇怪的字只出现在字的前面,是看不见的变戏法. 在
根据您提供的信息,您的问题不可重现:
试着自己复制它,像上面这样的方式,可以复制/粘贴到SO中,并显示出我做了什么和结果是什么。在
[Python 2.7.1;Windows 7 32位]
AFAIK,
search
和match
如果有捕获组,则返回一个匹配对象。要获得预期的行为,请使用findall
。在如果这不是你的疑问,请解释一下你到底想做什么。在
发布的代码应该可以找到匹配项。请注意,
re.search
返回一个MatchObject
,您不应该直接打印出它匹配的文本:这应该打印“共轭”。在
相关问题 更多 >
编程相关推荐