minibuffer

How to trim strings in Emacs Lisp?

October 13, 2023
(string-trim "  foo bar baz  ") ;; "foo bar baz"
(string-trim "-@-foo bar baz-_-" "[-@]+" "[-_]+") ;; "foo bar baz"
(string-trim-left "-@-foo bar baz" "[-@]+") ;; "foo bar baz"
(string-trim-right "foo bar baz-_-" "[-_]+") ;; "foo bar baz"