Sample text:
This is HeaderA
Line 1
Line 2
Line 3
Line 4
Line 5
This is HeaderB
Line 1
Line 2
Intended result:
HeaderA1 HeaderA2 HeaderA3 HeaderA4 HeaderA5
HeaderB1, HeaderB2
Regex Attempts:
(?:^This is (?P<H>HeaderB)\s) (Line (?P<L>\d)\s)*?
- Matches only the Header 'H' and 1st 'L' Line
(?:^This is (?P<H>HeaderB)\s)? (Line (?P<L>\d)\s)*?
- manage to match multiple 'L' Lines however, only first 2 line are of the same match, not the subsequent L lines does not reference the Header capture group.
I tried other attempts to adjust the regex but ended up screwing up the expression. I have limited experience with regex, so I am not entirely sure if it is possible to get the desired output.