Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Keep It Simple, Stupid
 
PerlMonks  

Re: Regex: Matching last of repeated character to end of string

by radiantmatrix (Parson)
on Nov 04, 2005 at 09:57 UTC ( [id://505722]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 10: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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://505722]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.