[英]Question about ,(?=(?:[^']*'[^']*')*[^']*$)
var result = Regex.Split(samplestring, ",(?=(?:[^\"]*\"[^\"]*')*[^\"]*$)");
我很難理解它是如何工作的。
具體來說,我不知道這里的 * 匹配什么?
",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")
^
是不是意味着
有 0 個或多個(?=(?:[^\"]*\"[^\"]*')
更新樣本輸入
2,1016,7/31/2008 14:22,Geoff Dalgas,6/5/2011 22:21,http://stackoverflow.com,"Corvallis, OR",7679,351,81,b437f461b3fd27387c5d8ab47a293d35,34
使用以下代碼進行測試:
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";
這意味着組(?:[^']*'[^']*')
匹配零次或多次。
, // 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
您可以檢查您的正則表達式並在此網站上進行測試:
http://www.annuaire-info.com/outil-referencement/expression-reguliere/
;) 玩得開心
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.