SPUG:Split question
Yitzchak Scott-Thoennes
sthoenna at efn.org
Fri Mar 21 17:40:31 CST 2003
On Fri, 21 Mar 2003 14:26:27 -0800, thane at fastmail.fm wrote:
>$string = "a,b,c,d,e,f,";
>@array = split /,/, $string;
>print "@array\n";
>
>Would print
>a, b, c, d, e, f,
>instead of
>a b c d e f
What a fasinating variety of ways that people have understood your
question! Here's my entry, answering the question as I read it:
@array = split /(?<=,)/, $string;
If your actual regex isn't subject to lookbehind, you need to use a
list context pattern match instead (untested):
@array = $string =~ /\G(.*?,|.*)/g
It may be tricky making sure you get it to work as you want with
e.g. multiple delimiters in a row or both delimiter at the end and not.
More information about the spug-list
mailing list