我有文本文件,文件的内容是这样的:
idiom: meaning
description.
o example1.
o example2.
idiom: meaning
description.
o example1.
o example2.
.
.
.如您所见,该文件包含上述段落,每个段落都有一些我希望提取的数据(请注意,示例以o开头)。例如,我们有以下数据:
public class Idiom
{
public string Idiom { get; set; }
public string Meaning { get; set; }
public string Description { get; set; }
public IList<IdiomExample> IdiomExamples { get; set; }
}
public class IdiomExample
{
public string Item { get; set; }
}有办法提取文件中的那些字段吗?知道吗?
编辑的
那个文件可以是任何东西,像成语和动词,.例如,这就是我的模式--例如:
little by little: gradually, slowly (also: step by step)
o Karen's health seems to be improving little by little.
o If you study regularly each day, step by step your vocabulary will increase.
to tire out: to make very weary due to difficult conditions or hard effort (also: to wear out) (S)
o The hot weather tired out the runners in the marathon.
o Does studying for final exams wear you out? It makes me feel worn out!预先感谢
发布于 2014-05-05 07:23:41
您的示例没有描述,但是这个regexp接受可选的描述。它让您了解如何解析输入,而不是整个C#代码。
请看这里的这个演示,看看这些组
(?smx)
^
([^:\n]+):\s*([^\n]+)
\n([^o].*?\n|)
(^o.*?)
(?=\Z|^[^o:\n]+:)在此之后:
此正则表达式不会将示例解析为几个示例,这是下一个工作。另外,你可能不喜欢一些新词。
https://stackoverflow.com/questions/23465773
复制相似问题