Basically, I want to split a multiline string at the regular expression that, in Perl, would be specified with \n(?=[^\W\d]\w*=)
.
Note that the Perl regexp features a "zero-width lookahead match" ((?=...)
), meaning that the substrings that match this part of the regexp will not be "consumed"; they will appear in their corresponding entries in the resulting list.
For example, the string whose printed representation is
A=1
B_C_D=
foo
bar
baz
=whatever=
X_Y_Z=quux
would be split into the following three-element list:
("A=1" "B_C_D=\nfoo\nbar\nbaz\n =whatever=" "X_Y_Z=quux\n")
Even though Elisp regexps do not support lookahead/lookbehind expressions, this sort of splitting problem (in which part or all of each matching substring is not consumed) is common enough that I hope there are some other standard ways to solve it in Elisp.
Moreover, the ultimate goal here is to split the output of the shell command
/usr/bin/zsh -ilc 'printenv' 2>/dev/null
so that each element of the result would correspond to one "setting" of an environment variable1. So I also figure that Elisp may possibly have functions that facilitate the handling of this special case2.
1 The desired result is conceptually similar to value of the variable process-environment
, but in general it is not be identical to it. Also, the side-effects associated with setting and updating process-environment
do not enter into my problem.
2 Unfortunately, it appears that process-environment
is initialized in C-code, so whatever functions do that are not available in Elisp.