【发布时间】:2012-12-21 06:41:01
【问题描述】:
我正在寻找以@ 开头并以第一个\s 结尾的子字符串。
@ 必须在字符串的开头或空格之后。
示例:@one bla bla bla @two @three@four #@five
结果:@one, @two, @three@four
我最终得到了这个回复:((?<=\s)|(?<=^))@[^\s]+,它在 sublime text 2 中运行良好,但在 python 中返回空字符串。
python 代码:
re.findall(r'((?<=^)|(?<=\s))@[^\s]+', '@one bla bla bla @two @three@four #@five')
【问题讨论】:
-
你是如何在 Python 中使用这个正则表达式的?
-
您不需要在第一个分支中进行回顾。
^已经是一个零宽度断言。
标签: python regex lookbehind