Parsing Text using RegExp

B

Barry

Hi

Sometime ago i had posted a request for code to parse a line of text
containing Quotes and Commas, the code posted by the gentleman did work for
sometime but does not work for the following

104528558,"New iPod FM Transmitter & Car Charger
$1Res(E107)","/Electronics-photography/Portable-audio-iPods/iPod-accessories/FM-Transmitters-iTrips","Jun
21 2007 12:28PM","Fixed price offer",29,"$6 Courier Nationwide (Rural +3)
No pick-ups allowed","$6.00 Courier Nationwide (Rural
+3)","kjc",,,"(e-mail address removed)",0,3.25,1.71,,1,1,39.95,"Jun 13 2007
9:00PM","7 days",,"yes","yes","yes","no","no","no",5,,"no"

the following is the code that does not work for the above
Regex regex = new
Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))");


Can someone help


Barry
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Barry said:
Sometime ago i had posted a request for code to parse a line of text
containing Quotes and Commas, the code posted by the gentleman did work for
sometime but does not work for the following

104528558,"New iPod FM Transmitter & Car Charger
$1Res(E107)","/Electronics-photography/Portable-audio-iPods/iPod-accessories/FM-Transmitters-iTrips","Jun
21 2007 12:28PM","Fixed price offer",29,"$6 Courier Nationwide (Rural +3)
No pick-ups allowed","$6.00 Courier Nationwide (Rural
+3)","kjc",,,"(e-mail address removed)",0,3.25,1.71,,1,1,39.95,"Jun 13 2007
9:00PM","7 days",,"yes","yes","yes","no","no","no",5,,"no"

the following is the code that does not work for the above
Regex regex = new
Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))");


Can someone help

What exactly do you mean by "does not work"?

I tried it, and it works just fine.
 
B

Barry

Yes, it does work, my question was slightly incorrect.

It works but return ONLY 26 of the 30 expected fields, whenever there are

"124",,,"152"
it will show return only 2 fileds not 4 for the above line

You can try to create a csv file with my line of text and open a excel sheet
for testing.

Correct me if i am wrong.



Göran Andersson said:
Barry said:
Sometime ago i had posted a request for code to parse a line of text
containing Quotes and Commas, the code posted by the gentleman did work
for sometime but does not work for the following

104528558,"New iPod FM Transmitter & Car Charger
$1Res(E107)","/Electronics-photography/Portable-audio-iPods/iPod-accessories/FM-Transmitters-iTrips","Jun
21 2007 12:28PM","Fixed price offer",29,"$6 Courier Nationwide (Rural +3)
No pick-ups allowed","$6.00 Courier Nationwide (Rural
+3)","kjc",,,"(e-mail address removed)",0,3.25,1.71,,1,1,39.95,"Jun 13 2007
9:00PM","7 days",,"yes","yes","yes","no","no","no",5,,"no"

the following is the code that does not work for the above
Regex regex = new

Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))");


Can someone help

What exactly do you mean by "does not work"?

I tried it, and it works just fine.
 
B

Barry

does it matter, for all you know i may not be trying to make a website at
all, i could be using it for a different purpose, that is immaterial for the
posting
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Barry said:
Yes, it does work, my question was slightly incorrect.

It works but return ONLY 26 of the 30 expected fields, whenever there are

"124",,,"152"
it will show return only 2 fileds not 4 for the above line

You can try to create a csv file with my line of text and open a excel sheet
for testing.

Correct me if i am wrong.



Göran Andersson said:
Barry said:
Sometime ago i had posted a request for code to parse a line of text
containing Quotes and Commas, the code posted by the gentleman did work
for sometime but does not work for the following

104528558,"New iPod FM Transmitter & Car Charger
$1Res(E107)","/Electronics-photography/Portable-audio-iPods/iPod-accessories/FM-Transmitters-iTrips","Jun
21 2007 12:28PM","Fixed price offer",29,"$6 Courier Nationwide (Rural +3)
No pick-ups allowed","$6.00 Courier Nationwide (Rural
+3)","kjc",,,"(e-mail address removed)",0,3.25,1.71,,1,1,39.95,"Jun 13 2007
9:00PM","7 days",,"yes","yes","yes","no","no","no",5,,"no"

the following is the code that does not work for the above
Regex regex = new

Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak>\\r\\n|\\n|$))");


Can someone help
What exactly do you mean by "does not work"?

I tried it, and it works just fine.

Yes, the pattern does not include empty items.

To make it include empty non-quoted items, change the first + to *.

To make it include empty quoted items, change the second + to *.
 
Top