Lets say I have some text in a file
AAAA k1="123" k2="456"
several lines of other stuff
AAAA k1="789" k2="101"
AAAA k1="121" k2="141"
The goal is to capture the k1 and k2 values, but keeping the groupings together. So the first match would return groups with 123 and 456, and the second match would return groups with 789 and 101, and 121 and 141.
I can write the regex to get any single line, or even match all the relevant lines in the file, but can't figure out how to keep the matches in groups.
The hardest thing about this is the number of lines that begin with AAAA are not constant across groups, for example that might be 1 AAAA line, then some other lines, then 4 AAAA lines, and so on.
EDIT -- Ok to clarify, the various values need to be kept separate by group.
So the first set of AAAA
lines only has one line, so I expect the values 123
and 456
.
The second set of AAAA
lines has 2 lines, so I need the values 789
,101
, 121
, and 141
. Moreover, I need to know the 789
and 101
are associated (came from the same line), and the 121
and 141
are associated (came from the same line), but still all part of the second group (not in any way associated with the 123
and 456
)
Eventually I want to get to objects (javascript) such as
{ '123': '456'}
and
{
'789': '101',
'121': '141
}
If there were 15 AAAA lines in a row, that object would have 15 key value pairs.