As approved in #4721 (comment), and later amended in #5125 (comment):
After the enhancement, only a <Max-substrings> value of 0 will be accepted as the explicit signal that all tokens should be returned, however many are found in the input string(s).
Negative <Max-substrings> values will work analogously to the already supported positive values, except that:
-
they return the specified number of strings from the end of the string(s).
-
all individually extracted tokens are returned in input order, and whatever unsplit part remains, if any, is returned as the first token.
Examples:
PS> 'a b c d' -split ' ', -2 # split into (at most) 2 strings from the end
a b c # prefix
d # requested token
PS> 'a b c d' -split ' ', -3 # split into (at most) 3 strings from the end
a b # prefix
c
d
PS> 'a b' -split ' ', -2 # 2 resulting strings - complete split; same as 0 in this case
a
b
Note that both -split ' ', 1 and -split ' ', -1 are no-ops: they request no splitting at all, and the sign of the <Max-substrings> argument is therefore irrelevant.
Reporting the prefix (unsplit part) first enables the following idiom:
PS> $prefix, $tokens = 'a b c d' -split ' ', -3 # -> $prefix = 'a b', $tokens = 'c', 'd'
Environment data
PowerShell Core v6.0.0-beta.8
As approved in #4721 (comment), and later amended in #5125 (comment):
After the enhancement, only a
<Max-substrings>value of0will be accepted as the explicit signal that all tokens should be returned, however many are found in the input string(s).Negative
<Max-substrings>values will work analogously to the already supported positive values, except that:they return the specified number of strings from the end of the string(s).
all individually extracted tokens are returned in input order, and whatever unsplit part remains, if any, is returned as the first token.
Examples:
Note that both
-split ' ', 1and-split ' ', -1are no-ops: they request no splitting at all, and the sign of the<Max-substrings>argument is therefore irrelevant.Reporting the prefix (unsplit part) first enables the following idiom:
Environment data