Explore Library
Code QuizIntermediate

Regex-Based Text Cleaning

Identify why whitespace is not collapsed during cleaning.

Codepython
import re

text = "This   is\ta   test"
# collapse all runs of whitespace into a single space
cleaned = re.sub(r"\s", " ", text)

print(repr(cleaned))

What is the bug in this whitespace-collapsing regex?