Regular expressions · 11 / 15 Exercise Medium

Hashtags and mentions

Objective

Create a Python program that extracts the hashtags and the mentions from a message with re.findall.

Instructions

  • Read a message.
  • Get the hashtags with re.findall(r"#\w+", message) and the mentions with re.findall(r"@\w+", message).
  • On the first line show Hashtags: followed by the hashtags separated by a space, in the order in which they appear. If there are none, show Hashtags: -.
  • On the second line show Mentions: with the same format.
Input
Hola @ana, mira esto #python #codigo con @luis
Output
Hashtags: #python #codigo
Mentions: @ana @luis

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise