in reply to Re: Irregular Expression??
in thread Irregular Expression??

I believe what you are actually looking for is
$a =~ s/\'/\\\'/g;
daN.

Replies are listed 'Best First'.
Re: Re: Re: Irregular Expression??
by jbware (Chaplain) on Feb 23, 2004 at 23:02 UTC
    Close, but I think this is actually what Red_Dragon is looking for:

    $a =~ s/\'/\\\'\\\'/g;

    Update: I was a bit too lazy on my copy job, you don't actually have to escape the '. So this will save you some keystrokes:
    $a =~ s/'/\\'\\'/g;

    -jbWare
      Assuming jbware's regex is correct (not testing it), wouldn't it be better to write:

      $a =~ s#'#\'\'#g;

      That way you aren't tracking around a bunch of backslashes? Or am I remembering wrong and s/// doesn't allow it?