Use the 'g' switch so the pattern match is
$mystring =~ s/\'/\\'/g;
This 'g' says do it for all occurrences (I remember it by thinking of it
as the 'g' in 'globally').
Dan
"J. Patrick Lanigan" wrote:
>
> I was using:
>
> $mystring =~ s/\'/\\'/;
>
> ...to replace ' with \' in $mystring. It was working find I thought, until I
> encountered a string with multiple apostrophies. How do I replace 0 or more?
>
> Ex:
>
> "No More 'I Love You's'"
>
> ...should become:
>
> "No More \'I Love You\'s\'"
>
> I've tried:
>
> $mystring =~ s/\'*/\\'/;
> $mystring =~ s/(\')*/\\'/;
>
> ...neither of which work.
>
> Any help would be greatly appreciated. And no cracks about the Annie Lennox
> song title, it is my wifes' part of our mp3 collection :-)
>
> Thanks,
> Patrick