Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Extract Hashtags from Social Media Text | Advanced Regular Expressions and Applications
Python Regular Expressions

bookChallenge: Extract Hashtags from Social Media Text

Instructions:

To further develop your skills with advanced regular expressions, your task is to create a function that extracts all hashtags from a social media post.

A hashtag is any word that starts with the # character, followed by one or more alphanumeric characters or underscores, and is not immediately preceded by another word character.

Your function should:

  • Handle hashtags at the beginning or end of the text;
  • Correctly extract hashtags surrounded by punctuation or whitespace;
  • Return all hashtags exactly as they appear in the text, including the # symbol.

Example:

Given the input:

"Excited for the #Python3_12 release! #coding #AI #100DaysOfCode"

you should return:

['#Python3_12', '#coding', '#AI', '#100DaysOfCode']

Use regular expressions to solve this challenge and pay special attention to edge cases.

Tarea

Swipe to start coding

Create a function that extracts all hashtags from a social media post. A hashtag is any word that begins with the # character, followed by one or more alphanumeric characters or underscores, and is not immediately preceded by another word character. Your function must correctly identify hashtags at the beginning or end of the text, as well as those surrounded by punctuation or whitespace. Return all hashtags exactly as they appear in the text, including the # symbol.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 3
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain how to handle hashtags that are adjacent to punctuation marks?

What should the function return if there are no hashtags in the text?

Could you provide more examples of valid and invalid hashtags?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Extract Hashtags from Social Media Text

Desliza para mostrar el menú

Instructions:

To further develop your skills with advanced regular expressions, your task is to create a function that extracts all hashtags from a social media post.

A hashtag is any word that starts with the # character, followed by one or more alphanumeric characters or underscores, and is not immediately preceded by another word character.

Your function should:

  • Handle hashtags at the beginning or end of the text;
  • Correctly extract hashtags surrounded by punctuation or whitespace;
  • Return all hashtags exactly as they appear in the text, including the # symbol.

Example:

Given the input:

"Excited for the #Python3_12 release! #coding #AI #100DaysOfCode"

you should return:

['#Python3_12', '#coding', '#AI', '#100DaysOfCode']

Use regular expressions to solve this challenge and pay special attention to edge cases.

Tarea

Swipe to start coding

Create a function that extracts all hashtags from a social media post. A hashtag is any word that begins with the # character, followed by one or more alphanumeric characters or underscores, and is not immediately preceded by another word character. Your function must correctly identify hashtags at the beginning or end of the text, as well as those surrounded by punctuation or whitespace. Return all hashtags exactly as they appear in the text, including the # symbol.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 3
single

single

some-alt