Link to home
Start Free TrialLog in
Avatar of kitwei
kitwei

asked on

\\ regex

Hi, my regex is just poor, please help me out here

I want to make sure my $string is double slashed as path separator, my $string can be

$string = "C:\temp\folder"
or
$string = "C:\\temp\\folder"

I have this
$string =~ s/\\/\\\\/g;
but it's wrong because the second $string will become
$string = "C:\\\\temp\\\\folder"

How to specify one \ only?

Thanks.
Avatar of iddo_levin
iddo_levin

Should work perfectly:

$string =~ s/\\(?!=\\)/\\\\/g;
Avatar of kitwei

ASKER

Hm... nope, I still get 4 \
ASKER CERTIFIED SOLUTION
Avatar of Sergy Stouk
Sergy Stouk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial