Regex Examples and Cookbook/Match leading or trailing spaces per line

Trim each line in multiline mode.

Section: Cleanup and Normalization

Match leading or trailing spaces per line

regex
regex
^\s+|\s+$
Explanation

Use multiline mode to trim line edges.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Cleanup and Normalization
Collapse blank lines
Match repeated blank lines.
OpenIn sheetregexsame section
Match Windows line endings
Find CRLF line endings.
OpenIn sheetregexsame section
Strip simple HTML-like tags
Match simple HTML tags for rough removal.
OpenIn sheetregexsame section
Normalize phone separators
Match common phone separators.
OpenIn sheetregexsame section
Redact card-like numbers
Find common 16-digit card-like sequences with separators.
OpenIn sheetregexsame section
UUID shape
Match a standard hyphenated UUID.