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.
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.
ASKER
Hm... nope, I still get 4 \
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$string =~ s/\\(?!=\\)/\\\\/g;