What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
To remove spaces, tabs, and line breaks everywhere in a Clojure string, use clojure.string/replace with a whitespace regular expression and an empty replacement: (str/replace s #"s+" ""). Unlike str/trim, this removes whitespace inside the string too.
Remove every whitespace run
Require clojure.string, then replace each run matched by s+ with the empty string:
(require '[clojure.string :as str])
(str/replace s #"s+" "")
clojure.string/replace replaces all matches when given a regular expression, so this removes whitespace at the beginning, between characters, and at the end of the string. The Clojure string API documents the regex pattern form.
(str/replace " hello t worldn" #"s+" "")
;; => "helloworld"
Deleting the separator joins adjacent text. This is useful when whitespace is unwanted in a compact token or identifier, but may be wrong for ordinary prose.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Choose whether to trim, delete, or collapse whitespace
| Intent | Clojure expression | Effect |
|---|---|---|
| Remove whitespace from both ends | (str/trim s) |
Preserves whitespace inside the string. |
| Remove whitespace from the left end | (str/triml s) |
Leaves the right end and interior unchanged. |
| Remove whitespace from the right end | (str/trimr s) |
Leaves the left end and interior unchanged. |
| Remove trailing line endings | (str/trim-newline s) |
Targets newline characters at the end, rather than all whitespace throughout. |
| Replace each whitespace run with one space | (-> s str/trim (str/replace #"s+" " ")) |
Trims the ends and preserves word separation while collapsing internal runs. |
The official Clojure string API documentation describes str/trim as removing whitespace from both ends; it does not remove internal whitespace.
(str/trim " hello t worldn")
;; => "hello t world"
(-> " hello t worldn"
str/trim
(str/replace #"s+" " "))
;; => "hello world"
Use the same pattern in ClojureScript
The ClojureScript clojure.string API documents the regex pattern form of replace as well. The same expression works for removing matched whitespace:
(require '[clojure.string :as str])
(str/replace s #"s+" "")
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Be explicit if Unicode whitespace matters
Clojure regex literals compile to java.util.regex.Pattern, as described in the Clojure language guide. The characters matched by a regex whitespace class can depend on the regex engine and its flags. If your application has a strict Unicode whitespace policy, define the exact characters it should remove and test that policy with representative inputs instead of assuming s covers every character your data may contain.
Quick Recap
Best Value
Rank #4
Rank #3
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute

