Reg Expression

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

All,

Looking for a regex expression to split this comma delimted string
ultimately into 51 fields. The fields in double quotes can have commas
within the quotes (separating values within the quotes - the issue I'm
having).


1208959596,Apr 23 2008 07:06:36,1208959607,Apr 23 2008
07:06:47,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0.00,0,0.00,0,0.00,0,1,"",
0,0,"Unknown,Unknown","Unknown",0,"","","Doctor,Pharmacy,101,true",
1,"","","S9V1T6LF0G1",0,"","","Service","","KioskReturningCustomer"


Thanks! (I'm working on this myself...)
 
Looch said:
Looking for a regex expression to split this comma delimted string
ultimately into 51 fields. The fields in double quotes can have commas
within the quotes (separating values within the quotes - the issue I'm
having).

1208959596,Apr 23 2008 07:06:36,1208959607,Apr 23 2008
07:06:47,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0.00,0,0.00,0,0.00,0,1,"",
0,0,"Unknown,Unknown","Unknown",0,"","","Doctor,Pharmacy,101,true",
1,"","","S9V1T6LF0G1",0,"","","Service","","KioskReturningCustomer"

I think you should split it manually without regex. Just loop through
the string and keep track of whether you are inside or outside quotes.

Arne
 
Looch said:
All,

Looking for a regex expression to split this comma delimted string
ultimately into 51 fields. The fields in double quotes can have commas
within the quotes (separating values within the quotes - the issue I'm
having).


1208959596,Apr 23 2008 07:06:36,1208959607,Apr 23 2008
07:06:47,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0.00,0,0.00,0,0.00,0,1,"",
0,0,"Unknown,Unknown","Unknown",0,"","","Doctor,Pharmacy,101,true",
1,"","","S9V1T6LF0G1",0,"","","Service","","KioskReturningCustomer"


Thanks! (I'm working on this myself...)


try this one:

Regex rgx = new Regex(",(\"[^\"]*\"),|,");
foreach (string s in rgx.Split(txt))
{
Console.WriteLine(s);
}

Regex is fun :)
 
Hello Looch,
Looking for a regex expression to split this comma delimted string
ultimately into 51 fields. The fields in double quotes can have commas
within the quotes (separating values within the quotes - the issue I'm
having).

1208959596,Apr 23 2008 07:06:36,1208959607,Apr 23 2008
07:06:47,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0.00,0,0.00,0
,0.00,0,1,"",
0,0,"Unknown,Unknown","Unknown",0,"","","Doctor,Pharmacy,101,true",
1,"","","S9V1T6LF0G1",0,"","","Service","","KioskReturningCustomer"

Why not use a OleDb provider to load this as a comma seperated file and use
ADO.NET to load the data into a dataset. Much faster and easier than parsing
them out in a Regular Expression. \
 
Looch said:
All,

Looking for a regex expression to split this comma delimted string
ultimately into 51 fields. The fields in double quotes can have commas
within the quotes (separating values within the quotes - the issue I'm
having).


1208959596,Apr 23 2008 07:06:36,1208959607,Apr 23 2008
07:06:47,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00,0.00,0.00,0,0.00,0,0.00,0,1,"",
0,0,"Unknown,Unknown","Unknown",0,"","","Doctor,Pharmacy,101,true",
1,"","","S9V1T6LF0G1",0,"","","Service","","KioskReturningCustomer"


Thanks! (I'm working on this myself...)

Here:
https://vkarlsen.serveftp.com:8443/svn/LVK/LVK_3_5/trunk/LVK.Core/Text/StringUtils.cs
https://vkarlsen.serveftp.com:8443/svn/LVK/LVK_3_5/trunk/LVK.Core/Text/SmartSplitOptions.cs
login is "guest" for both username and password, without the quotes.

The method you want is StringUtils.SmartSplit, it can be passed a list
of quote characters and split characters, and will not consider split
characters between quotes.

To parse your string:

String[] parts = StringUtils.SmartSplit(s, new Char[] { '"' }, new
Char[] { ',' }, SmartSplitOptions.Default);

Just make a copy of the method and the enum if you wish to use it, no
need to keep the rest of that class.
 
Back
Top