Skip to content
uencoder
TASK

Extract hashtags from text

Hashtags start with # followed by letters, numbers, and underscores. Learn to extract, validate, and normalize hashtags from social media text.

  1. 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. 2
    Regex Tester →

    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. 3
    Regex Replace →

    Normalize 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>.

Frequently asked questions

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.

Workflows that solve this

Learn more

Want to understand why?

Related tools