我有一个大型正则表达式,用于解析我自己的类似于 lua 的文件格式。这很好用,除了引号内的数字以某种方式匹配两次,即使 split 不应该返回重叠的结果。我已将其简化为这个控制台应用程序。有任何想法吗?
static void Main(string[] args)
{
string pattern = "(\r\n)|(\"(.*)\")"; // Splits at \r\n and anything in "quotes"
string input = "\"01\"\r\n" + // "01"
"\"02\"\r\n" + // "02"
"\"03\"\r\n"; // "03"
string[] results = Regex.Split(input, pattern );
foreach (string result in results )
{
//This just filters out the split \r\n and empty strings in results
if (string.IsNullOrWhiteSpace(result) == false)
Console.WriteLine(result);
}
Console.ReadLine();
}
回报:
"01"
01
"02"
02
"03"
03