MediumText Processing
Extra Space Detector
Write a regex intended for use with .replace() to detect runs of two or more consecutive spaces in a string, so they could be collapsed down to a single space.
//
'hello world' / 'hello world' / 'a b' / 'single space here' / ' leading'
Test cases
- hello worldexpect match
- hello worldexpect no match
- a bexpect match
- single space hereexpect no match
- leadingexpect match
- notrailing expect match
How to Solve this Regex Challenge
To complete the Extra Space Detector challenge, you must write a regular expression pattern that satisfies all specified test cases.
Steps to Complete:
- Analyze the Requirements: Read the description and review the list of test cases below. Identify which strings must be matched (green markers) and which must be rejected (red markers).
- Draft Your Pattern: Enter your regex in the interactive editor. Use the provided Hint button if you get stuck.
- Verify: The test cases panel will update in real-time as you type, showing which strings match your current expression.
- Review the Solution: Once you successfully pass all test cases, review the explanation to understand the logic behind the solution.