tools / regex library / hashtag
regex pattern · ready to copy

Regex for matching hashtags (#tag)

Match `#`-prefixed hashtags. Letters, digits, underscores; no spaces. Unicode-letter friendly.

intermediate javascript / pcre / python4 use cases

The pattern

#[\p{L}\p{N}_]{1,140}

Looser variant (more permissive, fewer false rejects):

#[A-Za-z0-9_]{1,140}

Test cases

InputResult
#voiddomatches
#100DaysOfCodematches
#日本matches
#with spacerejects
##doublerejects
no-hashrejects

Edge cases & caveats

Must use Unicode-aware mode (`\p{L}`) for non-Latin scripts (Japanese, Cyrillic, Arabic). In JavaScript, set `u` flag. ASCII-only mode misses real hashtags in non-English social posts.

Common use cases

Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab  

Related

username · bitcoin address · email address · hex color