Twitter 用户名的正则表达式

问题描述:

您能否提供一个与 Twitter 用户名匹配的正则表达式?

Could you provide a regex that match Twitter usernames?

如果提供 Python 示例,则额外奖励.

Extra bonus if a Python example is provided.

(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9-_]+)

我使用它是因为它不考虑电子邮件.

I've used this as it disregards emails.

这是一个示例推文:

@Hello @you 好吗@my_friend,给我发邮件@000 @ whats.up@example.com @shahmirj

@Hello how are @you doing @my_friend, email @000 me @ whats.up@example.com @shahmirj

匹配:

  • @你好
  • @你
  • @my_friend
  • @shahmirj

它也适用于主题标签,我使用相同的表达式,将 @ 更改为 #.

It will also work for hashtags, I use the same expression with the @ changed to #.