Rexexp. Big text with hierarchy
I have a text of law, with Chapters and Articles.
Chapter 1. Something
Article 1. trata-trata
Article 2. trata-trata
Article 3. trata-trata
Chapter 2. Something
Article 4. trata-trata
Article 5. trata-trat开发者_运维百科a
Article 6. trata-trata
I need regexp, to find Articles within Chapters, and know what articles belongs to what Chapter. (C# preferably)
Regex
isn't best solution for your problem. You should to parse your text line by line and to store your Articles
inside your Chapter
structure.
string line = "";
StreamReader data = new StreamReader("your file.txt");
List<Chapter> chapters = new List<Chapter>();
while ((line = data.ReadLine()) != null)
{
if (line.StartsWith("Chapter"))
{
chapters.Add(new Chapter(line));
}
else if (line.StartsWith("Article"))
{
chapters[chapters.Count - 1].Articles.Add(new Article(line));
}
}
精彩评论