具有鍵/值對(duì)的“緊密”重復(fù)模式的字符串(在此示例中,鍵為“名稱”,值應(yīng)為單個(gè)小寫字母)string text = "name: abc name: def name: ghi name: jkl";應(yīng)該轉(zhuǎn)換為輸出abc,def,ghi,jkl,而模式中的任何干擾(可以說(shuō)是“非緊”)string text = "name: abc x name: def name: ghi name: jkl";應(yīng)該導(dǎo)致匹配失敗,類似abc,##發(fā)生異常:x無(wú)法與模式##匹配我試過(guò)了string text = "name: abc name: def name: ghi name: jkl";string pattern = @"name:\s*([a-z])*\s*";MatchCollection ms = Regex.Matches(text, pattern);foreach (Match m in ms){ Console.Write(m.Groups[1].Value+", ");}但它返回c,f,i,l,是什么導(dǎo)致這種奇怪的行為,我該如何解決?
“緊密”重復(fù)的鍵/值匹配
喵喵時(shí)光機(jī)
2021-04-07 13:14:14