给定一个简单的字符串,如 "@dasweo where you at?"
我想编写一个正则表达式来提取 "dasweo"
。
我目前拥有的是:
print re.findall(r"@\w{*}", "@dasweo where you at?")
虽然这不起作用。谁能帮我解决这个问题?
最佳答案
去掉 {..}
大括号,它们不与 *
一起使用:
>>> re.findall(r"@\w*", "@dasweo where you at?")
['@dasweo']
仅使用具有固定数字的 {..}
量词:
\w{3}
例如,正好匹配 3 个字母。
关于python - 从字符串中获取 Twitter 用户名的简单正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18190930/