Regular Expressions 101

Community Patterns

hashtag and user tag regex

1

Regular Expression
PCRE (PHP <7.3)

/
(@[\w\.]*)|(#\w[^#\W]+)
/
gi

Description

This regular expression can be used to find tags and hashtags in a string. It assumes that a username can contain both underscores and points (.) and that hashtags can only contain letters

Submitted by Luca Simonetti - 9 years ago