Skip to Content
0
Aug 07, 2008 at 07:56 AM

Regular Expression Help

18 Views

Hi there,

can anyone help me with a regular expression.

I want to replace all delimiting commas in a CSV string with another character. The string contents look something like this...

1,10,Johnson,"Stores and Sales",High,10031984,paycycle1,"red,blue,green",full

...so what I want to change it to is this...

1|10|Johnson|"Stores and Sales"|High|10031984|paycycle1|"red,blue,green"|full

My problem is with the regex syntax. The closest I have got to is...

,(?![^"]*")

..but this produces the result...

1,10,Johnson,"Stores and Sales",High,10031984,paycycle1,"red,blue,green"|full

...as it only matches the commas after the last " delimited field.

Any help appreciated.

Cheers

Graham Robbo