in reply to In place replace, ignoring between quotes

here one pure regex solution using /e eval-option to handle different cases:
DB<151> $str=$str0 => " bla0 \"ignore a1\" bla1 \"ignore a2\" bla2" DB<152> $str =~ s/("[^"]*?"|a)/ $1 eq "a" ? "A" : $1 /ge => 5 DB<153> $str => " blA0 \"ignore a1\" blA1 \"ignore a2\" blA2"

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: In place replace, ignoring between quotes (one regex)
by LanX (Saint) on Oct 25, 2013 at 21:41 UTC
    even shorter and more general in usage:

    DB<229> $_=$str0 => " bla0 \"ignore a1\" bla1 \"ignore a2\" bla2" DB<230> s/("[^"]*")|a/ $1 or 'A' /ge => 5 DB<231> $_ => " blA0 \"ignore a1\" blA1 \"ignore a2\" blA2"

    or for the OP

    DB<226> $_=q{cd / ; /path/to/R/R_latest --vanilla --args "fName='rGS +DPlan';jobCode=682718;jobId=6827181;" < job682718.R > job_6827181.txt +} DB<227> s/("[^"]*")|;/ $1 or '&&' /ge => 2 DB<228> $_ => "cd / && /path/to/R/R_latest --vanilla --args \"fName='rGSDPlan';j +obCode=682718;jobId=6827181;\" < job682718.R > job_6827181.txt"

    Cheers Rolf

    ( addicted to the Perl Programming Language)