Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Regular Expression Help

by pg (Canon)
on Nov 18, 2005 at 20:16 UTC ( #509937=note: print w/ replies, xml ) Need Help??


in reply to Regular Expression Help

Or utilize rindex: (this code works regarless whether there is a trailing /)

use strict; use warnings; { my $str = "/rootdir/sub1/sub2/sub3/sub4/"; print substr($str, 0, rindex($str, "/", length($str) - 2)); } print "\n"; { my $str = "/rootdir/sub1/sub2/sub3/sub4"; print substr($str, 0, rindex($str, "/", length($str) - 2)); }

which prints:

/rootdir/sub1/sub2/sub3 /rootdir/sub1/sub2/sub3


Comment on Re: Regular Expression Help
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-10-26 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls