Need help ignoring commas within a csv file

  • Thread starter Thread starter zdrakec
  • Start date Start date
Z

zdrakec

I need to be able to do a Regex.split on a csv file ignoring the comma
if it is inside a single quote. I have the regular expression working
in the RegexDesigner tool, but when I use it within vb.net it adds an
extra split on each of the commas as well.

Example:
Reg Ex = ,(?=([^']*'[^']*')*(?![^']*'))
String to split = " '1A', 9, 2884, 'Sally, is late', 'nothing'

Works fine in the designer but output in vb.net looks like
element(0) = '1A'
element(1) = ,
element(2) = 9
element(3) = ,

etc...

Any help will be greatly appreciated!!

Thanks,
zdrakec
 
Despite the common thinking, regex's do not work for csv's. Even if you
find a regex that is somewhat close to handling what you need, it will
be slower than even the simplest string manipulation. If you're doing
this for production code, I would strongly recommend that you use one
of the several production level csv parsers available on the net.

Bruce Dunwiddie
http://www.csvreader.com
 
Back
Top