Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

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


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://505722]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2025-03-17 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (54 votes). Check out past polls.