jmmach80 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to remove/replace all occurrences of a semicolon, except for the very last. I've been messing around with various regular expressions, but I just can't quite get it right.
Take this example for instance:
my $string = "I have multiple ; in my string; however I want to keep t +he last one;"
I need a regular expression that'll remove/substitute all the ; except the last one.
$string =~ s/<regex>//; print "$string\n"; I have multiple in my string however I want to keep the last one;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quick regex substitution question
by stevieb (Canon) on May 29, 2015 at 14:16 UTC | |
by stevieb (Canon) on May 29, 2015 at 21:15 UTC | |
by jmmach80 (Initiate) on May 29, 2015 at 14:21 UTC | |
|
Re: Quick regex substitution question
by toolic (Bishop) on May 29, 2015 at 14:13 UTC | |
|
Re: Quick regex substitution question
by hdb (Monsignor) on May 29, 2015 at 14:11 UTC | |
by jmmach80 (Initiate) on May 29, 2015 at 14:18 UTC | |
by ww (Archbishop) on May 29, 2015 at 16:02 UTC |