C# Regex Split - commas outside quotes
var result = Regex.Split(samplestring, ",(?=(?:[^\"]*\"[^\"]*')*[^\"]*$)");
I have problems to understand how it works.
Specifically, I don't know what the * matches here?
",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")
^
Does it mean
there are 0 or more of (?=(?:[^\"]*\"[^\"]*')
update for a 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 the following code to 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 that the group (?:[^']*'[^']*')
is matched zero or more times.
, // match one comma
(?= // Start a positive lookAHEAD assertion
(?: // Start a non-capturing group
[^']* // Match everything but a single-quote zero or more times
' // Match one single-quote
[^']* // Match everything but a single-quote zero or more times
' // Match one single-quote
)* // End group and match it zero or more times
[^']* // Match everything but a single-quote zero or more times
$) // end lookAHEAD
You could check your regex and make your test on this website:
http://www.annuaire-info.com/outil-referencement/expression-reguliere/
;) have fun
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.