newbie: emacs 'split-string'
Quote:
> Hi folks,
> I have a problem with the emacs lisp 'split-string' function.
> Let's say I want to split the string "abc" at every match of the
> regular expression "a+". The expression (split-string "bab" "a+")
> evaluates to ("b" "b"), which is fine.
> On the other hand, (split-string "abc" "a+") evaluates to ("bc")
> instead of to ("" "bc"). This means, there is no leading empty
> string, despite the leading match. So in a sense, 'split-string' does
> not really 'split'. We loose information about the matches at the
> beginning (and at the end).
> In which way can I obtain the desired behavior?
Sure, add the leading and trailing empty strings by hand,
conditionally. Pseudocode:
Do the usual split-string
(when (string-match (concat "^" regex) string)
add a leading ""
)
(when (string-match (concat regex "$") string)
add a trailing ""
)
You'll want to build the regular expressions a little more carefully
in case they already begin/end with bol/eol, but I'm sure you get the
idea.
Quote:
> I'm not claiming there is anything wrong with 'split-string', I simply
> need a different function.
--
Tom Breton, http://world.std.com/~tob
Not using "gh" since 1997. http://world.std.com/~tob/ugh-free.html
Rethink some Lisp features, http://world.std.com/~tob/rethink-lisp/index.html