本文介绍了正则表达式返回术语而不是术语之间的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
public void DeserialStream(string filePath)
{
using (StreamReader sr = new StreamReader(filePath))
{
string currentline;
Regex countRegex = new Regex("\"DataType\",\"(?:Count|Net)\"((?!\"DataType\").)*", RegexOptions.Singleline);
while ((currentline = sr.ReadLine()) != null)
{
foreach (Match match in countRegex.Matches(currentline))
{
Console.WriteLine(match.Value);
}
}
}
}
这是我的CSV:
"Date","dd/mm/yyyy"
"ExpirationDate","dd/mm/yyyy"
"DataType","Count"
"Location","Unknown","Variable1","Variable2","Variable3"
"A(Loc3, Loc4)","Unknown","5656","787","42"
"A(Loc5, Loc6)","Unknown","25","878","921"
"DataType","Net"
"Location","Unknown","Variable1","Variable2","Variable3"
"A(Loc3, Loc4)","Unknown","5656","787","42"
"A(Loc5, Loc6)","Unknown","25","878","921"
我想在下面的DataType,Count和DataType,Net之间返回数据。但是,我的编译器返回的术语:DataType,Count和DataType,Net,而不是之间的数据。我不知道我做错了什么?
I want to return the data between "DataType", "Count" and "DataType", "Net" below. However, my compiler is returning the terms: "DataType", "Count" and "DataType", "Net" and not the data in between. I'm not sure what I am doing wrong?
推荐答案
我认为这种模式会做 \DataType\,\Count\\ \\(。*?)\DataType\,\Net\
w / s
选项
I think this pattern will do \"DataType\",\"Count\"(.*?)\"DataType\",\"Net\"
w/ s
option
Demo
这篇关于正则表达式返回术语而不是术语之间的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!