I'm trying to extract the PROCEDURE section out of CLAIM, EOB & COB from a text file.
and create an object like so
claim : [{PROCEDURE1}, {PROCEDURE2}, {PROCEDURE3}],
eob : [{PROCEDURE1}, {PROCEDURE2}, {PROCEDURE3}],
cob: [{PROCEDURE1}, {PROCEDURE2}, {PROCEDURE3}]
let data = ` SEND CLAIM {
PREFIX="9403 "
PROCEDURE { /* #1 */
PROCEDURE_LINE="1"
PROCEDURE_CODE="01201"
}
PROCEDURE { /* #2 */
PROCEDURE_LINE="2"
PROCEDURE_CODE="02102"
}
PROCEDURE { /* #3 */
PROCEDURE_LINE="3"
PROCEDURE_CODE="21222"
}
}
SEND EOB {
PREFIX="9403 "
OFFICE_SEQUENCE="000721"
PROCEDURE { /* #1 */
PROCEDURE_LINE="1"
ELIGIBLE="002750"
}
PROCEDURE { /* #2 */
PROCEDURE_LINE="2"
ELIGIBLE="008725"
}
PROCEDURE { /* #3 */
PROCEDURE_LINE="3"
ELIGIBLE="010200"
}
}
SEND COB {
PREFIX="TEST4 "
OFFICE_SEQUENCE="000721"
PROCEDURE { /* #1 */
PROCEDURE_LINE="1"
PROCEDURE_CODE="01201"
}
PROCEDURE { /* #2 */
PROCEDURE_LINE="2"
PROCEDURE_CODE="02102"
}
PROCEDURE { /* #3 */
PROCEDURE_LINE="3"
PROCEDURE_CODE="21222"
DATE="19990104"
}
PRIME_EOB=SEND EOB {
PREFIX="9403 "
OFFICE_SEQUENCE="000721"
PROCEDURE { /* #1 */
PROCEDURE_LINE="1"
ELIGIBLE="002750"
}
PROCEDURE { /* #2 */
PROCEDURE_LINE="2"
ELIGIBLE="008725"
}
PROCEDURE { /* #3 */
PROCEDURE_LINE="3"
ELIGIBLE="010200"
}
}
}`
let re = /(^\s+PROCEDURE\s\{)([\S\s]*?)(?:})/gm
console.log(data.match(re));
Here is what I have tried so far (^\s+PROCEDURE\s\{)([\S\s]*?)(?:}), but I can't figure out how I can match PROCEDUREs after key CLAIM or EOB

PRIME_EOB=SEND EOBto be skipped?CLAIMsection then parsePROCEDUREand add it to results object, and so on for other keys. if you have a cleaner / better idea that would be great, thanks"SEND EOB"appears twice, at two different "levels".PRIME_EOB=SEND EOB, as I am not clear as to how it should be dealt with.