Extraer hashtags from text
Hashtags iniciar con # followed por letters, números, y underscores. Aprender a extraer, validar, y normalizar hashtags de social media texto.
- 1
A hashtag is # followed by one or more word characters (letters, digits, underscores), with no spaces. Some platforms allow Unicode letters. The regex #[\w]+ (or #[^\s#]+ for more permissive matching) finds hashtags. Normalize by converting to lowercase and stripping the # for storage.
- 2 Probador de regex →
Find all hashtags with #[\w]+ (ASCII) or #[\p{L}\p{N}_]+ (Unicode, requires u flag). Test against social media text: "Loving #WebDev and #JavaScript2024! #Frontend". The tool shows all matches.
- 3 Reemplazo con regex →
Normalizar hashtags: convert to lowercase, remove the # prefix, and deduplicate. Replace #([\w]+) with the lowercase version for consistent storage. Link hashtags to search pages by replacing #tag with <a href="/search?q=tag">#tag</a>.
Preguntas frecuentes
- What characters are allowed in hashtags?
- Most platforms allow letters, digits, and underscores. Some (Twitter/X, Instagram) allow Unicode letters (CJK, Arabic, emoji). Punctuation, spaces, and special characters end the hashtag. The # must be at the start or preceded by a space (otherwise it is part of a word, like C#).
- Should hashtags be case-sensitive?
- No — #WebDev and #webdev should be treated as the same tag. Normalize to lowercase for storage and comparison. Display in the original case if desired, but group by the lowercase form. This ensures consistent search and aggregation.