Regular Expression For Twitter @username

Category: Strings

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:

See Also:

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.