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:
Sven
|
Source |
|
Your Rating |
|
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).