A regular expression to match unnecessary whitespaces in a string (excluding spaces between words). Can be useful in removing all unexpected white spaces at the beginning or end of strings.
/^\s+|\s+$|\s+(?=\s)/
Matches:
- RegexPattern<SPACE>
- <SPACE>RegexPattern
Non-matches:
- Regex<SPACE>Pattern
See Also:
- Regex To Match All Whitespace Except New Line
- Regular Expression To Match Whitespace
- Regex To Match Any Word In A String Excluding Spaces
- Regex To Match Whitespaces Between Words
- Regex To Match A String With No Whitespace At The Beginning And End
- Regex To Match Anything After The First Space In A String
- Regex To Match Everything Except Letters And Spaces