小编Pri*_*iya的帖子

使用正则表达式匹配不以某个字母开头的单词

我正在学习正则表达式,但无法在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']
Run Code Online (Sandbox Code Playgroud)

预期: ['is','a']

python regex regex-negation regex-lookarounds

4
推荐指数
1
解决办法
1182
查看次数

标签 统计

python ×1

regex ×1

regex-lookarounds ×1

regex-negation ×1