in reply to Re: Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0
in thread Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0
For completeness, here's WHY this fixes your function so you can maybe avoid similar issues in the future.
$text = "O'REILLY"; $text =~ s/'/\\'/g; # $text is now O\'REILLY $text =~ s/"/\\"/g; # Unchanged $text =~ s/\\/\\\\/g; #$text is not O\\'REILLY
So you properly replace it with a single backslash, but then you tell it to replace all single backslashes with double backslashes. If you wanted to do this properly, move the 3rd line above the 1st. But everyone is right, use the module.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0
by lancer (Scribe) on Jul 27, 2012 at 08:00 UTC |