【发布时间】:2021-05-15 14:16:48
【问题描述】:
如果我运行以下代码:
import re
s = "I love #stackoverflow because #people are very #helpful! #???? #Here"
x = re.findall(r"#(\w+)", s.lower())
print(x)
输出是
['stackoverflow', 'people', 'helpful', 'here']
但我也想阅读 # 之后的表情符号,输出为:
['stackoverflow', 'people', 'helpful', '????', 'here']
我怎样才能做到这一点?
【问题讨论】:
-
\w用于 alnum 字符(a-z、0-9)和下划线。表情符号不是这样的字符。您可能正在寻找非空白字符:\S -
@yedpodtrzitko 使用这个 re.findall(r"#(\S+)", s.lower()) 没有帮助。