Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://314698]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-01-17 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (158 votes). Check out past polls.