I frequently need to split strings, while keeping the separator
. Researching the elisp manual, I am not finding a way to split a string according to a separator, without consuming the separator itself.
For example, split-string
splits a given string into substrings based on the regular expression separators, but the substrings lose the separator:
(split-string "* one * two * three" "\*")
returns:
("" " one " " two " " three")
I could use s-slice-at
, from @magnars s.el
(s-slice-at "\*" "* one * two * three")
("* one " "* two " "* three")
I could also try to rewrite split-string
myself. Still, I was wondering if there is a built-in way to do it as part of Emacs core?
If not, could somebody please point to a good way to do that properly?
s-slice-at
with a different name?s.el
)?split-string
to do what you want. The code ofs-slice-at
isn't great anyway, since it uses recursion.