Current area: HOME -> Blogs -> Jonathan's Blog

$jonathan.ramble(topic => 'work' & 'play');

My random-ish ramblings about my work at Programmer's Heaven and on the Parrot project, my crazy conference schedule and whatever else I feel like posting.
Splitting CSV with regex
Posted on Wednesday, November 21, 2007 at 6:01 AM
I answered a question on the Perl forum today about splitting CSV. CSV is a comma separated format; for example:
blah,blah,blah
You can put values in quotes:
blah,"blah blah",blah
And those quotes make commas within them meaningless too:
blah,"blah,blah,blah",blah
If we do the naive thing and implement it using split on a comma:
my @fields = split(/,/, $string);
Then we will obviously get the Wrong Answer. The question was, is there a regex we can use with split that will do the Right Thing? And the answer was yes, though it took me a few minutes to come up with it. The thing is that we don't want to match anything more than the commas we are splitting on, but we do need to do some analysis on the string that is up ahead (or behind us) to detect if the comma we are seeing is in quotes.

Read More

Subscribe

RSS Feed RSS Feed

By Tag

AJAX ASP.NET Automated Build Tool C# C# 3.0 conferences CSV DSL FinalBuilder Inside PH Linq parallelism Perl Programmer's Heaven Programming Subversion types Version Control Visual Studio 2008 Windows Vista

By Month

February 2008
January 2008
December 2007
November 2007
October 2007

Help

Check out the Blog FAQ.


Sponsored links

Software Localization Tool Sisulizer
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
DVD/CD Duplicators - All Free Shipping
Simple Disc-to-Disc Duplication. 2 Year Warranty & Free Shipping.
-software
-software, Try 4 Different Flavors Today, Pay Only Shipping Fee.


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.