score:-1

You need to change your file format. I would suggest storing this as structured data in an RDBMS or MongoDB as being the easiest solution, but if you want to use your own log format, you need to structure it so you know the start and end of each chunk, and the section/child number is structured so you don't need to use a regex.

Here is one possible solution. Each separate chunk is a JSON object, and is stored on its own line. So lines from your file could look like:

{"section": "1", "path": "/", "info": "Info for section1\nNext Line of info\nAnd so on..."}
{"section": "3", "path": "/child2/child1", "info": "Info for child1 of child2 which is child of section3"}

Related Query

More Query from same tag