Turning on warnings would've helped here.$directory =~ s<^/*></> . </*$></>;
cchampion fixed his RE so I can't explain why it doesn't work, cause now it does.
What I've been able to make work is something that recognizes the _middle_ of your string, not either end. This is a translation out of Perl Cookbook, 2ndEd. (cargo-cult of a higher order?)
Update: I take too long typing! And my solution only takes one '/' off each end. I guess I took so long typing that "I forgot the question" ;-)$directory =~ s< ^ /? # match leading '/' if present ( # capture what is between ends [^/]* # match anything not a '/' (?: # might be a '/', (?! /$ ) # but don't allow a '/' at EOL . # okay, eat the '/' ) * ) /? $ # match trailing '/' > </$1/>x; # now surround the middle with '/'
In reply to Re: Regex - one and only one / at beginning and end of file path
by shenme
in thread Regex - one and only one / at beginning and end of file path
by mikedshelton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |