Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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: (7)
As of 2014-12-22 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls