in reply to Why doesn't this s/regex// work?
A few Monks have already explained why your regex was not working as you expected, let me add my two cents concerning other methods you can (and probably should) use with simple strings like the one you have there.
# With split my $code = q(fruit:red:apple); my @parts = split /:/, $code; pop @parts; my $parent = join ':', @parts; # With substr and rindex (my favourite, and probably the fastest) my $code = q(fruit:red:apple); my $parent = substr($code, 0, rindex($code, ':'));
|
|---|