Last active
October 11, 2017 08:30
-
-
Save kobapan/da10f10a11def6c9886a to your computer and use it in GitHub Desktop.
文字列の先頭及び末尾から空白(又は指定文字)を取り除く emacs lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun trim (string &optional needle) | |
"Remove needle at the beginning and endding of string." | |
(let ((n (if needle needle "[ \t\n\r]+")) | |
(s (if (string-match (concat "\\`" n) string) ; "\`" バッファや文字列の先頭 | |
(replace-match "" t t string) | |
string))) | |
(if (string-match (concat n "+\\'") s) ; "\'" バッファや文字列の末尾 | |
(replace-match "" t t s) | |
s))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment