RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find CSV exported from Excel (all variants)
Expression
;?(?:(?:"((?:[^"]|"")*)")|([^;]*))
Description
This expressions parses one line from a CSV file which has been written with Excel. It does cover all variants: simple value, value masked by double quotes (including semicolons between double quotes which don't count) and double quotes masked by double quotes (""). Replace all semicolons within the regex to change the separator character.
Matches
abc;efg;"Column with ;";"Column with ; and ""double quotes""";;ijk;
Non-Matches
abc,efg,'test',ijk
Author Rating: The rating for this expression. Sven Jacobs
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Better variant
Name: FractalizeR
Date: 8/25/2007 5:00:02 PM
Comment:
This would be a better variant I think: Captures including empty values: ((?:(?:"(?:(?:[^"]|"")*)")|(?:[^;]*))) Captures excluding empty values: ((?:(?:"(?:(?:[^"]|"")*)")|(?:[^;]+)))


Title: and empty Values???
Name: Robert P
Date: 5/9/2007 4:01:50 AM
Comment:
I am new to Regular Expressions, excuse me. What's about empty values? Why do we need the ; in our match? I changed your Expression into this one "([^"]|"")*"|[^;]+|(?<=;)(?=;) Now there is no group for getting the values, if you need something like that (?:(?:"((?:[^"]|"")*)")|([^;]*))|(?<=;)(?=;) would be the right one. Please explain your Expression! Thanks.


Title: please explain
Name: Sven Jacobs
Date: 12/6/2006 4:15:32 AM
Comment:
Please explain what you mean. Quotes will be returned, I know.


Title: not bad,
Name: David Oldfield
Date: 11/20/2006 5:39:45 PM
Comment:
not bad... but it is inconsistent with output of quotes (text qualifiers).


Copyright © 2001-2014, RegexAdvice.com | ASP.NET Tutorials