in reply to Re: Strip bad characters from a string
in thread Strip bad characters from a string

Instead of just stripping them, how do I make a ' into a \' and " into a \". I tried using your example and adapting it but the result was \\\\\\\\\\\\\\\\\\\\\\\\\\\\' because it keeps looping just looking for the single character. Any ideas appreciated. Ian.

Replies are listed 'Best First'.
RE: RE: Strip bad characters from a string
by btrott (Parson) on Apr 11, 2000 at 22:04 UTC
    Try
    s#(['"])#\\$1#g;
    Result (using the same string that I used the first time):
    \'foo\' is in single quotes, \"bar\" is in double quotes, and there are carriage returns between