Perl stripping regex with delimiter-prefix

I want to split if before separator if there is no special character.

my $str = "a,b,c,d,e";
my @lst = split (/,/, $str);

# gives me: ("a", "b", "c", "d", "e")

# now I want to split after any , with not a character c in front of the ,.
# ("a", "b", "c,d", "e")

      

I tried

split (/(?!c),/, $str)

      

but it didn't work as expected.

+3


source to share


1 answer


Use a negative lookahead for a statement for what checks back.



split (/(?<!c),/, $str)

      

+3


source







All Articles