Based on my previous question, I've come up with a better way to approach my problem. Here's what I have in mind:
- I want to start extracting word/space characters up to the first occurrence of a pipe ('|') delimiter, or else a newline. Trim whitespace at either end. This extraction will be the start of a new "entry".
- For each pipe found (if any), I want to remove the pipe, then extract everything up to the next occurrence of a pipe or newline. Trim whitespace. Everything extracted will be a parameter for above "entry".
- For the next occurrence of a newline:
- If the newline begins with a pipe, or the previous line ended with one, I want to remove the newline like it wasn't there.
- Otherwise, I want to begin anew from step 1 with a new "entry".
Here's some sample input:
This will be a new entry | param1 |param2 |etc.
This is another entry, but without params
This is a third entry|with a twist
| I'm using subsequent lines for
| its parameters.
Yet I still want the next line to be another new entry.
And this should be the output:
Entry #1: "This will be a new entry"
Params: ["param1","param2","etc."]
Entry #2: "This is another entry, but without params"
Entry #3: "This is a third entry"
Params: ["with a twist","I'm using subsequent lines for","its parameters."]
Entry #4: "Yet I still want the next line to be another new entry."
What would be a good way to go about doing this?