I have a multi-line text like the following
#####1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
#####2
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
#####3
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
#####I
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
#####II
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
(there's an empty line at the end, despite what SO thinks). I need to split this along the headings, keeping the heading text, and putting the whole thing in a dictionary/hash table/associative array/whatever you call it using the heading text as keys (they are unique).
I tried to iterate through the lines but my brain is too fried up right now to get this right -- I get each text shifted ahead by one, heading 1 ends up empty, and heading II ends up with the text from heading I.
I was thinking I could do this with a regex, so I came up with this
#####(.+)\n([\w\W\n]+?)#
which obviously captures the "next" #
, thus it only captures odd headings.
Ideas? (I'm language-agnostic, so feel free to answer in the one you prefer).
OK, that was embarrassingly easy. As it turns out, splitting on
#####
was perfectly acceptable.