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 having an uproarious good time at the Monastery: (8)
As of 2015-07-08 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls