c# - Question about ,(?=(?:[^']*'[^']*')*[^']*$) -
c# regex split - commas outside quotes
var result = regex.split(samplestring, ",(?=(?:[^\"]*\"[^\"]*')*[^\"]*$)");
i have problems understand how works.
specifically, don't know * matches here?
",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)") ^
does mean
there 0 or more of (?=(?:[^\"]*\"[^\"]*')
update sample input
2,1016,7/31/2008 14:22,geoff dalgas,6/5/2011 22:21,http://stackoverflow.com,"corvallis, or",7679,351,81,b437f461b3fd27387c5d8ab47a293d35,34
use following code test:
string samplestring = "2,1016,7/31/2008 14:22,geoff dalgas,6/5/2011 22:21,http://stackoverflow.com,\"corvallis, or\",7679,351,81,b437f461b3fd27387c5d8ab47a293d35,34";
it means group (?:[^']*'[^']*')
matched 0 or more times.
, // match 1 comma (?= // start positive lookahead assertion (?: // start non-capturing group [^']* // match single-quote 0 or more times ' // match 1 single-quote [^']* // match single-quote 0 or more times ' // match 1 single-quote )* // end group , match 0 or more times [^']* // match single-quote 0 or more times $) // end lookahead
Comments
Post a Comment