Im trying to remove unwanted characters from CSV data in the community version of Mule ESB. Because its a regex problem I thought I
would ask for advice here. I want to remove line feeds from CSV data so the changes would be

Code:
     aa,bb,cc,"aa
     bb",dd,ee
becomes

Code:
     aa,bb,cc,"aabb",dd,ee
I also want to remove comma's from within columns so

Code:
     aa,bb,cc,"aa,bb",dd,ee
becomes

Code:
     aa,bb,cc,"aabb",dd,ee
and finally I want to remove bar characters ( for onward processing to a Hadoop cluster ). So

Code:
     aa,bb,cc,"aa|bb",dd,ee
becomes
Code:
     aa,bb,cc,"aabb",dd,ee
The last action is easy, in a Mule script I do somethng like this

Code:
 payload.toString()
   .replaceAll(  '([^"])\\,([^"].*$)',  '$1$2')
   .replaceAll(  '([^"])\n([^"].*$)',  '$1$2')
   .replaceAll(  '\\|',                       ''  );
Ignoring the function call ( replaceAll ) can anyone advise how I match the \n character and the , ( comma ) character in CSV data
when the column is within double quotes ? The example commands above dont work properly, they take the sample input data
Code:
 ,,,,"abdgc|mm,mmaaaaa",,,,,
 ,,,,"abdgc|mm,mma
 aaaa",,,,,
 ,,,,"abdgc|mm,mmaaaaa",,,,,
and turn it into this
Code:
 ,,,"abdgcmmmmaaaaa",,,,,,"abdgcmmmmaaaaa",,,,,,"abdgcmmmmaaaaa",,,
so too many comma's and line feeds are removed. Any advice on the actual regex to use would be good. The complex
column to be processed could be any column number .. its not fixed. The data above is just simple for testing.