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
| Input | Result |
|---|---|
| #voiddo | ✓matches |
| #100DaysOfCode | ✓matches |
| #日本 | ✓matches |
| #with space | ✗rejects |
| ##double | ✗rejects |
| no-hash | ✗rejects |
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
- social analytics extraction
- tag-cloud generation
- trending detection pipeline
- campaign attribution
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