9
>>> import re
>>> s = 'this is a test'
>>> reg1 = re.compile('test$')
>>> match1 = reg1.match(s)
>>> print match1
None
在Kiki中匹配s结尾处的测试。我错过了什么? (我试过re.compile(r'test$')
以及)正则表达式 - 匹配返回无。我错在哪里?
>>> import re
>>> s = 'this is a test'
>>> reg1 = re.compile('test$')
>>> match1 = reg1.match(s)
>>> print match1
None
在Kiki中匹配s结尾处的测试。我错过了什么? (我试过re.compile(r'test$')
以及)正则表达式 - 匹配返回无。我错在哪里?
您的正则表达式不匹配匹配整个字符串。您可以使用搜索而不是无用提到的,或者你可以改变你的正则表达式匹配的完整的字符串:
'^this is a test$'
还是有些难读,但不那么没用:
'^t[^t]*test$'
这取决于你在做什么。
谢谢,我完全忘了这两个操作的区别:) – tetris555
谢谢! ()(( 我现在花了两个小时,试图找出问题在rx大声笑 – oriadam