Regex for @mention
/(?<![\w@])@[A-Za-z0-9_]{1,15}\b/g
Matches
Examples
Note
The lookbehind skips the @ in an email address.
Matches in the example
"@ana""@bob_92"
Token by token
(?<!not preceded by (negative lookbehind)[\w@]one of: a word character (letter, digit or _) or “@”)end of group@the character “@”[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\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma