A one-liner regex is
not the most maintainable or efficient solution to this problem. But since you asked, here's a regex answer:
| | | s/((?:^|\|)(?:[^"|]*"[^"|]*")*[^"|]*)"([^"|]*)(?=$|\|)/$1$2/g;
|
The readability of that could be improved upon, however:
| | | my $T = qr/[^"|]*/;
s/((?:^|\|)(?:$T"$T")*$T)"($T)(?=$|\|)/$1$2/go;
|
Now here's how I would have really done it:
| | | join '|', map { s/"([^"]*)$/$1/ if y/"// & 1; $_ } split /\|/;
|
MeowChow
s aamecha.s a..a\u$&owag.print