Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Mask Sensitive Information | Advanced Regular Expressions and Applications
Python Regular Expressions

bookChallenge: Mask Sensitive Information

Masking Sensitive Information with Regular Expressions

In many real-world scenarios, you need to protect sensitive information within text, such as credit card numbers. Using regular expressions, you can locate these numbers and mask them effectively. Your goal is to write a function that replaces all but the last four digits of every credit card number in a given string with asterisks (*). The masked result should:

  • Preserve the original number's length and formatting;
  • Expose only the last four digits for identification.

Example:

  • Input: "My card is 1234-5678-9012-3456";
  • Output: "My card is ****-****-****-3456".

Use Python's re module to implement this solution.

Tarea

Swipe to start coding

You need to protect sensitive information in text, such as credit card numbers. Your task is to create a function that locates every credit card number in a string and masks all but the last four digits with asterisks ("*"). Credit card numbers may appear as 16 consecutive digits or be separated by spaces or hyphens, and the masking must preserve the original length and formatting. Only the last four digits should remain visible for identification.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 4
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 show me how to write the regular expression for this task?

Can you explain how to preserve the original formatting while masking the digits?

Can you provide a complete Python function for this masking process?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Mask Sensitive Information

Desliza para mostrar el menú

Masking Sensitive Information with Regular Expressions

In many real-world scenarios, you need to protect sensitive information within text, such as credit card numbers. Using regular expressions, you can locate these numbers and mask them effectively. Your goal is to write a function that replaces all but the last four digits of every credit card number in a given string with asterisks (*). The masked result should:

  • Preserve the original number's length and formatting;
  • Expose only the last four digits for identification.

Example:

  • Input: "My card is 1234-5678-9012-3456";
  • Output: "My card is ****-****-****-3456".

Use Python's re module to implement this solution.

Tarea

Swipe to start coding

You need to protect sensitive information in text, such as credit card numbers. Your task is to create a function that locates every credit card number in a string and masks all but the last four digits with asterisks ("*"). Credit card numbers may appear as 16 consecutive digits or be separated by spaces or hyphens, and the masking must preserve the original length and formatting. Only the last four digits should remain visible for identification.

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 4
single

single

some-alt