DevKits

Extraction

Match a hashtag

Flags: g

Extract hashtags (#topic) from social media style text.

Pattern

Regular expression

#\w+

How it works

Matches `#` followed by one or more word characters. Simple and effective for latin-alphabet hashtags.

Matches

  • #coding
  • #WebDev
  • #100DaysOfCode

Non-matches

  • # space (space breaks it)
  • just text

Common gotchas

For non-Latin hashtags (Chinese, Arabic, emoji), use the Unicode-aware pattern: `#[\p{L}\p{N}_]+` with the `u` flag in JS.

Language snippets

JavaScript

const re = /#\w+/g;
"#dev #webdev".match(re); // ["#dev", "#webdev"]

Python

re.findall(r"#\w+", "#dev #webdev")

Go

re := regexp.MustCompile(`#\w+`)
re.FindAllString("#dev #webdev", -1)

Java

Pattern.compile("#\\w+")

Related patterns

Try any pattern live in the Regex Tester