Normalize whitespace without altering punctuation or letter casing
=IF(
text="",
"",
TRIM(
REGEXREPLACE(
SUBSTITUTE(text, CHAR(160), " "),
"\s+",
" "
)
)
)
NORMALIZE_WHITESPACE cleans up spacing in a text string while leaving punctuation, capitalization, and wording unchanged. It trims leading/trailing whitespace, converts non-breaking spaces into regular spaces, and collapses any repeated whitespace (including tabs and line breaks) into single spaces. This is useful for cleaning messy copy/paste text, form inputs, or imported data before matching, comparing, or displaying it. For example, if A2 contains " Hello world this is fine ", the result is "Hello world this is fine"
Use the inputs below to create NORMALIZE_WHITESPACE as a reusable custom function in Google Sheets.
Learn how to add custom functions to Google SheetsNORMALIZE_WHITESPACE
Normalize whitespace without altering punctuation or letter casing
=IF( text="", "", TRIM( REGEXREPLACE( SUBSTITUTE(text, CHAR(160), " "), "\s+", " " ) ) )
text
Text to clean and normalize spacing
A2
Other functions in the same category: Text Manipulation & Formatting
Lowercases text, trims it, removes punctuation, and collapses whitespace
Returns the nth word from a text string
Returns the nth word from the end of a text string
Return uppercase initials from a name or phrase
Removes diacritics from text (for example é to e, ü to u)
Removes HTML tags and decodes a few common HTML entities
Named functions enable the creation of custom, reusable formulas that mimic built-in functions, streamlining calculations and data manipulations. These functions simplify complex formulas, making spreadsheets more readable and less prone to errors. By encapsulating intricate logic within a single function call, they enhance consistency across your data. Utilizing named functions reduces the need to write lengthy formulas repeatedly, thereby improving workflow efficiency and productivity in data analysis and management.
Download and import — fastest way to add the function but does not include argument descriptions and examples
Follow these simple steps to download and import a function into your spreadsheet. This method is the quickest and easiest way to add the named function to your Google Sheets document, but will not include the argument description and examples.
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.
Copy and paste — copy and paste each property one at a time
Follow these simple steps to integrate a custom named function into your spreadsheet:
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.