Currently suffering from writers block trying to come up with an elegant solution to this problem.
Take the following example:
{
"data": {
# Some information about field 1
# on multiple lines
"field1": "XXXXXXXXXX",
# Some more info on a single line
"field2": "XXXXXXXXXXX",
"field3": "#this would be ignored"
}
}
From the above, I'd like to extract the code comments together as a group, rather than individually. This grouping would happen if a line was commented right after another line. Comments will always start with whitespace followed by a #.
Example result:
Capture group 1: Some information about field 1\n on multiple lines
Capture group 2: Some more info on a single line
I could step over the lines and evaluate in code, but it would be nice to use a regex if possible. If you feel like a regex is not the correct solution for this problem, please explain your reasons why.
SUMMARY:
Thank you to everyone for submitting various solutions to this problem, this is a prime example of just how helpful the SO community can be. I will be spending an hour of my own time answering other tickets to make up for the collective time spent on this.
Hopefully this thread will help others in future too.