文本提取的问题---正则表达式
1.从文本文件提取: \Title到 \thanks 之间的内容,可能中间有换行。我用此句:
MatchCollection mc = Regex.Matches(txtContent, "\\title'>(?<content>(.*\n)*?.*?)(?=\\thanks", RegexOptions.IgnoreCase);
总是提示:
正在分析“title'>(?<content>(.*
)*?.*?)(?=thanks”- ) 不足。
string path = @"L:\\";
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileInfo file in dir.GetFiles())
{
if (file.Extension.Equals(".txt"))
listBox1.Items.Add(file.FullName);
{
string filePath = file.FullName;
string txtContent = File.ReadAllText(filePath, Encoding.GetEncoding("UTF-8"));
MatchCollection mc = Regex.Matches(txtContent, "title'>(?<content>(.*\n)*?.*?)(?=thanks", RegexOptions.IgnoreCase);
foreach(Match m in mc)
{
textBox1.Text= m.Groups["content"].Value;
}
}
}
}
}
2.比如我要提取:
\begin{Section}
............
......
\end{Section}
如何使用比较高效率的正则表达式? 最好是有个例子。
谢谢。 文本提取 --------------------编程问答-------------------- string pattern=@"(?is)(?<=title).*?(?=thanks)";
补充:.NET技术 , C#