The sample code above removes all white spaces and new lines using regex and replaces them with a single space. As you can see the original string within
text is extremely messy, with multiple irregular spaces and unnecessary new lines. However, after using the
replace() function (part of the String Object), the string is completely different and looks like a proper sentence with one space between each word. Without using regular expressions, trying to accomplish a task like this requires
for loops and multiple lines of code.