我正在寻找以@
开头的子串,并以第一个\s
的发生结束。 必须在字符串开头或空格后有@
。python正则表达式有条件lookbehind
例:@one bla bla bla @two @[email protected] #@five
结果:@one, @two, @[email protected]
我结束了这种重:((?<=\s)|(?<=^))@[^\s]+
它工作在崇高的文本2罚款,但在Python返回空字符串。
Python代码:
re.findall(r'((?<=^)|(?<=\s))@[^\s]+', '@one bla bla bla @two @[email protected] #@five')
你如何使用这个表达式在Python? – Blender
你不需要在第一个分支倒序。 '^'已经是一个零宽度的断言。 –