【发布时间】:2018-10-26 17:18:57
【问题描述】:
我正在学习正则表达式,但无法在 python 中找到正确的正则表达式来选择以特定字母开头的字符。
以下示例
text='this is a test'
match=re.findall('(?!t)\w*',text)
# match returns
['his', '', 'is', '', 'a', '', 'est', '']
match=re.findall('[^t]\w+',text)
# match
['his', ' is', ' a', ' test']
预期:['is','a']
【问题讨论】:
-
[i for i in text.split() if i[0] != 't']
标签: python regex regex-negation regex-lookarounds