Imagine having a text file with the following content:
AAAA k1="123" k2="456"
several lines of other stuff
AAAA k1="789" k2="101"
AAAA k1="121" k2="141"
The objective is to extract the values of k1 and k2 while keeping them grouped together. For instance, the first match should return 123 and 456 as a pair, the second match should return 789 and 101, and 121 and 141 for the third match.
I can create a regex pattern to get each line individually or even capture all relevant lines in the file, but I'm struggling to figure out how to maintain these matches in groups.
The challenge lies in the varying number of AAAA lines between groups - it could be one line, then some different lines, followed by four AAAA lines, and so on.
EDIT -- To clarify, the distinct values from each group must be kept separate.
In the case where there's only one AAAA
line within a group, I expect the values 123 and 456.
If there are two AAAA
lines in a group, like in the second set, I need to retrieve 789, 101, 121, and 141. Furthermore, it's crucial to distinguish that 789 and 101 belong together (from one line) and 121 and 141 form another pair within the same group, completely separate from the 123 and 456 values.
Ultimately, I aim to convert this data into JavaScript objects, such as:
{ '123': '456'}
and
{
'789': '101',
'121': '141'
}
If there were 15 consecutive AAAA lines, the resulting object would contain 15 key-value pairs.