Regex for @mention

/(?<![\w@])@[A-Za-z0-9_]{1,15}\b/g

Options
Matches

Examples

Note

The lookbehind skips the @ in an email address.

Matches in the example

  • "@ana"
  • "@bob_92"

Token by token

  1. (?<! not preceded by (negative lookbehind)
  2. [\w@] one of: a word character (letter, digit or _) or “@”
  3. ) end of group
  4. @ the character “@”
  5. [A-Za-z0-9_]{1,15} one of: “A” to “Z”, “a” to “z”, “0” to “9” or “_”, between 1 and 15 times, as many as possible
  6. \b a word boundary

Other patterns