David Boland

David Boland

  • NA
  • 11
  • 0

Regex Troubles

Jan 25 2010 10:30 AM
I am trying to parse a file using the following regex:

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

It works well except if there is a blank field. (i.e, two commas in a row, or two quotes in a row) I need it to return a blank string.

Any suggestions.

Sample text would be: there is a line feed at the end of each line and a carriage return/line feed after the header row and after each set of invoices.

Fax_#,Email,Supplier,Name,Address,Contact,Amount_Paid,System_Date,Deposit_Date,Invoice_Details
(555)555-5555,"[email protected]","20033","CITY OF SAU1","RANT STREET
2ND ADDRESS LINE
SAU  WI 54783

","","  $85730.93",19 NOV 2009,23 NOV 2009, " (I)INV0908763  CUSTOMER#116                    11/01/09   $8907.88
 (I)INV0908993  CUSTOMER#116                    11/01/09     $12.61
 (I)INV0908992  CUSTOMER#116                    11/01/09    $405.72
 (I)INV0909222  CUSTOMER#116                    11/05/09  $76344.80
 (I)INV0909406  CUSTOMER NO: 116                11/12/09     $59.92
"
(555)555-5555,"[email protected]","20033","CITY OF SAU1","RANT STREET
SAU  WI 54783

","","  $85730.93",19 NOV 2009,23 NOV 2009, " (I)INV0908763  CUSTOMER#116                    11/01/09   $8907.88
 (I)INV0908993  CUSTOMER#116                    11/01/09     $12.61
 (I)INV0908992  CUSTOMER#116                    11/01/09    $405.72
 (I)INV0909222  CUSTOMER#116                    11/05/09  $76344.80
 (I)INV0909406  CUSTOMER NO: 116                11/12/09     $59.92
"
(555)555-5555,"[email protected]","20033","CITY OF SAU1","RANT STREET
SAU  WI 54783

","","  $85730.93",19 NOV 2009,23 NOV 2009, " (I)INV0908763  CUSTOMER#116                    11/01/09   $8907.88
 (I)INV0908993  CUSTOMER#116                    11/01/09     $12.61
 (I)INV0908992  CUSTOMER#116                    11/01/09    $405.72
 (I)INV0909222  CUSTOMER#116                    11/05/09  $76344.80
 (I)INV0909406  CUSTOMER NO: 116                11/12/09     $59.92
"


Answers (3)