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+")

Frequently asked questions

What is the regex for hashtag?

The pattern #\w+ (flags: g) matches hashtag. Matches `#` followed by one or more word characters. Simple and effective for latin-alphabet hashtags.

What does this hashtag pattern match?

It matches strings like #coding, #WebDev, #100DaysOfCode, but rejects # space (space breaks it), just text.

How do I use this pattern in JavaScript, Python, Go, Java?

Ready-to-run snippets are provided for JavaScript, Python, Go, Java. Copy the one for your language from the Language snippets section — each wraps the same core pattern in that language's regex API.

What are common pitfalls with a hashtag regex?

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

Related patterns

Try this pattern in a tool

Try any pattern live in the Regex Tester