Regexdrill

Level 4: Extraction and cleanup Exercise 35 of 52 Pro

Hashtags

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

Capture every hashtag's text, without the #, in group 1. A hashtag is # followed by word characters, and the # must be at the start of the line or right after whitespace.

What this exercise teaches

(?:^|\s)#(\w+) skips a # glued to other text, as in an email address, and captures the tag after it.

A hint if you get stuck

Require the start of the line or a whitespace character before the #, without capturing it.

This exercise is part of Pro

Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Extraction and cleanup