tags:

views:

157

answers:

3

This is the sample

"abc","abcsds","adbc,ds","abc"

Output should be

abc
abcsds
adbc,ds
abc

A: 

Try this:

"(.*?)"

if you need to put this regex inside a literal, don't forget to escape it:

Regex re = new Regex("\"(.*?)\"");
Rubens Farias
If use this // line read from .csv filestring line ="\"abc\",\"abcsds\",\"adbc,ds\",\"abc\"";string [] abc = Regex.Split(line,"\"(.*?)\"");Outputabc[0] ="" <br>abc[1] ="abc" <br>abc[2] ="," <br>abc[3] ="abcsds" <br>abc[4] ="," <br>abc[5] ="adbc,ds" <br>abc[6] ="," <br>abc[7] ="abc" <br>abc[8] ="" <br>
Venkat Gurram
Sorry, I didn't understood; can you please edit your question?
Rubens Farias
btw, what language are you using?
Rubens Farias
C# string line="\"abc\",\"abcsds\",\"adbc,ds\",\"abc\"";
Venkat Gurram
string [] abc = Regex.Split(line,"\"(.*?)\"");
Venkat Gurram
Output abc[0] ="", abc[1] ="abc" , abc[2] ="," , abc[3] ="abcsds" , abc[4] ="," , abc[5] ="adbc,ds" , abc[6] ="," , abc[7] ="abc" , abc[8] ="" –
Venkat Gurram
Thansk if I use this "\",\"" it spilts all the values within "" and i will replace "" with blank
Venkat Gurram
A: 

This is a tougher job than you realize -- not only can there be commas inside the quotes, but there can also be quotes inside the quotes. Two consecutive quotes inside of a quoted string does not signal the end of the string. Instead, it signals a quote embedded in the string, so for example:

"x", "y,""z"""

should be parsed as:

x
y,"z"

Jerry Coffin
I does not have double quotes insdie at all
Venkat Gurram
A: 

If you can be sure there are no inner, escaped quotes, then I guess it's ok to use a regular expression for this. However, most modern languages already have proper CSV parsers.

Use a proper parser is the correct answer to this. Text::CSV for Perl, for example.

However, if you're dead set on using regular expressions, I'd suggest you "borrow" from some sort of module, like this one: http://search.cpan.org/~abigail/Regexp-Common-2.122/lib/Regexp/Common/balanced.pm

genio