Looking for some help tweaking this split command.
The objective is to copy one chunk of text and paste it into a report that has 3 sections. I need the middle section to accept multiple lines and the way I have this right now, its splitting for part 3 based on the hard return after "Neoplastic effusion" line instead of the Tab after "inflammation"
My goal is to write something like this in a Google doc...
And I'd like the number of lines in that middle "Interpretation" section to be flexible. Meaning some reports have only one line there and others need 4. Is that possible with the splitregx or do I need to do this a different way? if so... how?
{run: raw = replaceregex({clipboard}, "\r", "", "g")
problem = ""
if testregex(raw, "\t")
var parts = splitregex(raw, "\t")
head = trim(parts[1])
comment = trim(join(slice(parts, 2), "\t"))
else
var blocks = filter(splitregex(raw, "\n\s*\n"), b -> len(trim(b)) > 0)
if count(blocks) < 3
problem = "Could not find 3 sections in the clipboard. Leave a blank line after the description and after the interpretation, or put a Tab at the end of the interpretation."
head = raw
comment = ""
else
head = join(slice(blocks, 1, count(blocks) - 1), "\n\n")
comment = trim(blocks[count(blocks)])
endif
endif
var hblocks = filter(splitregex(head, "\n\s*\n"), b -> len(trim(b)) > 0)
if count(hblocks) > 1
description = trim(join(slice(hblocks, 1, count(hblocks) - 1), "\n\n"))
interpretation = trim(hblocks[count(hblocks)])
elseif count(filter(map(splitregex(head, "\n"), l -> trim(l)), l -> len(l) > 0)) > 1
var lines = filter(map(splitregex(head, "\n"), l -> trim(l)), l -> len(l) > 0)
description = lines[1]
interpretation = join(slice(lines, 2), "\n")
else
description = trim(head)
interpretation = ""
problem = "Could not find an interpretation section in the clipboard."
endif
interpretation = join(map(splitregex(interpretation, "\n"), l -> trim(l)), "\n")