因此,我想编写一个正则表达式,该正则表达式与一个比单词少一个字符的单词匹配。因此,例如:
wordList = ['inherit', 'inherent']
for word in wordList:
if re.match('^inhe....', word):
print(word)
从理论上讲,它将同时打印继承和固有的内容,但我只能使其打印固有的内容。因此,如何在不删除一个点(。)的情况下将一个字母短的单词与之匹配?
(编辑)
要只匹配固有的,可以使用.{4}
:
re.match('^inhe.{4}', word)
或....$
:
re.match('^inhe....$')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句