in reply to Recommendations for parsing invalid CSV
You could use look-behind (?<= ) and look-ahead (?= ) expressions to look only for quotes which are not beside a comma or at end and start of the line:
s/(?<=.)(?<!,)"(?!,|$)/\\"/g A simple test in the command line brings me:
s/(?<=.)(?<!,)"(?!,|$)/\\"/g A simple test in the command line brings me:
The 2nd line is input, the 3rd output.user@machine$ perl -pe 's/(?<=.)(?<!,)"(?!,|$)/\\"/g' "call from "friend"","call from "friend"","call from "friend"" "call from \"friend\"","call from \"friend\"","call from \"friend\""
Looks good for me. Some special cases with escaped commas inside the strings might not match correctly. You should check this.
In Section
Seekers of Perl Wisdom