Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Don't ask to ask, just ask
 
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: (17)
As of 2014-04-18 18:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls