Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regex - one and only one / at beginning and end of file path

by cchampion (Curate)
on Dec 14, 2003 at 22:46 UTC ( #314698=note: print w/ replies, xml ) Need Help??


in reply to Regex - one and only one / at beginning and end of file path

If you want to use one regex only, you must add an alternation and thus a /g option, because you need to match two times.

$directory =~ s{ (?: ^ /* | (?<=[^/])/* $ ) }</>xg;

Update added a look-behind assertion to make the expression work in all cases. All in all, it's better with two regexes!


Comment on Re: Regex - one and only one / at beginning and end of file path
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-02-01 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    On my keyboard, Caps lock is:








    Results (5 votes), past polls