in reply to Regex: Matching last of repeated character to end of string

There are three approaches I can think of that would solve your issue, and only one is a regex.

  1. The regex solution:
    $xpath =~ s{/[^/]+$}{};
  2. The split solution:
    my @temp = split('/', $xpath); $xpath = join('/',@temp[0..$#temp-1]);
  3. The rindex solution:
    $xpath = substr($xpath,0,rindex($xpath,'/'));

The last one (rindex) strikes me as the most efficent way to go, but I haven't Benchmarked it.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

Replies are listed 'Best First'.
Re^2: Regex: Matching last of repeated character to end of string
by japhy (Canon) on Nov 04, 2005 at 15:04 UTC
    Or even substr($xpath, rindex($xpath, '/')) = "";!

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart