在字符串中
s = 'Makeupby Antonia #makeup #makeupartist #makeupdolls #abhcosmetics'
我只想匹配不以#
开头的单词。意味着我只想选择Makeupby
和Antonia
我试着用否定的先行断言
re.findall(r'\b(?![#])[a-zA-Z]+',s)
['Makeupby',
'Antonia',
'makeup',
'makeupartist',
'makeupdolls',
'abhcosmetics']
但这和所有的词都匹配。我错在哪里?你知道吗
Tags:
(?!)
是负向前看的语法。你想要一个负面的观察。你知道吗试试
\b(?<!#)[a-zA-Z]+
Demo
相关问题 更多 >
编程相关推荐