Regex To Match All Whitespace Except New Line

A regular expression to match all whitespaces except new links in your content.

Can be useful in replacing a string of text that includes 1 or more blank spaces with a new value in only certain places.

/[^\S\r\n]+/g

Matches:

  • Any spaces but new lines

Non-matches:

  • new lines
  • abc
  • 123

See Also:

Regex Is Copied!