Skip to main content

trim_whitespace

Trims leading and trailing whitespace from a string and replaces internal whitespace sequences with a single space using regular expressions.

def trim_whitespace(
s: string
) - > string

Removes leading and trailing whitespace from a string and collapses all internal whitespace sequences into a single space.

Parameters

NameTypeDescription
sstringThe input string containing potential leading, trailing, or redundant internal whitespace to be normalized.

Returns

TypeDescription
stringThe cleaned string with normalized spacing, suitable for consistent display or storage.