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

A one-liner that uses only one backslash:
s/(')/\Q$1$1/g; # Or s/'/\Q''/g;
Without backslashes:
s/(')/quotemeta "$1$1"/eg;

Abigail

Replies are listed 'Best First'.
Re: Re: Irregular Expression??
by Skeeve (Parson) on Feb 26, 2004 at 08:26 UTC
    Normally you correct me. This time I have to tell you, you're wrong - sorry.

    The OP really wanted \'\' to appear for every '!

    So you're missing the \-part too.
      This time I have to tell you, you're wrong - sorry.
      Really? I tested my solution, did you?
      #!/usr/bin/perl use strict; use warnings; my $str = "A'Bcd"; $_ = $str; s/(')/\Q$1$1/g; print "$_\n"; $_ = $str; s/'/\Q''/g; print "$_\n"; $_ = $str; s/(')/quotemeta "$1$1"/eg; print "$_\n"; __END__ A\'\'Bcd A\'\'Bcd A\'\'Bcd
      Seems to print \'\' for every ' to me.

      Abigail