Challenge: Replace Multiple Spaces with a Single Space
Instructions: Clean Up Extra Spaces with Regex
Text data often contains inconsistent spacing, such as multiple consecutive spaces between words. You need to write a function that uses regex substitution to convert any sequence of multiple spaces into a single space, making the text cleaner and easier to process.
- Use the
remodule for your solution; - Replace every sequence of two or more consecutive spaces with a single space;
- Ensure the function returns the cleaned string.
Swipe to start coding
You are given a string that may contain extra spaces between words. Your task is to write a function that cleans up the text by replacing every sequence of two or more consecutive spaces with a single space. This will make the text easier to read and process. Use regular expressions to accomplish this.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Can you show me an example input and the expected output?
What should the function do if there are leading or trailing spaces?
Do you want the function to handle tabs or only spaces?
Awesome!
Completion rate improved to 6.67
Challenge: Replace Multiple Spaces with a Single Space
Swipe um das Menü anzuzeigen
Instructions: Clean Up Extra Spaces with Regex
Text data often contains inconsistent spacing, such as multiple consecutive spaces between words. You need to write a function that uses regex substitution to convert any sequence of multiple spaces into a single space, making the text cleaner and easier to process.
- Use the
remodule for your solution; - Replace every sequence of two or more consecutive spaces with a single space;
- Ensure the function returns the cleaned string.
Swipe to start coding
You are given a string that may contain extra spaces between words. Your task is to write a function that cleans up the text by replacing every sequence of two or more consecutive spaces with a single space. This will make the text easier to read and process. Use regular expressions to accomplish this.
Lösung
Danke für Ihr Feedback!
single