Regular Expression For Twitter @username

I use this regular expression to validate Twitter username. If a user enters a valid Twitter username that includes @, it will be matched.

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

Matches:

  • @google
  • @regex_pattern
  • @regex-pattern

Non-matches:

  • @regex/pattern
  • regexpattern
  • regexpattern@

See Also: