The first field (f1, etc.) is guaranteed to be unique, and it (and the "details" bit) will always match something in var_Main.
What I need to do: For each line in var_Subset, I need the first field inserted into the matching row in var_Main, replacing the ??. If the order of var_Main didn't matter, I'd be fine—it's not trivial (for me), but I had it working in one version.
But I'm stuck trying to figure out how to do this while maintaining the order. I can find matches easily, but after that, I'm unsure how to say "take the first bit from this particular match in var_Subset and insert it at the first field of the corresponding line in var_Main.
It almost seems like I need two nested "for each" loops, but my first attempt at that was something of a disaster.
The answer was indeed two "for each" loops, one inside the other. Basically, for each row in var_Main that matches a criteria I set, I then loop through each row in var_Subset looking for the exact match. Once I have that, I can do a find/replace back into var_Main without messing up the sort order:
Yep, that worked perfectly, and is much simpler. In the end, the bit that had me going to two loops was this relatively simple part of the regex:
I couldn't figure out how to capture the line with the ?? knowing I had letters in the to-be-matched string instead of ??.
I did have to make one modification, and that was my fault, not yours: For the sake of an easy demonstration, I used a very simplified data set in my post. In the real data, the "details" part is a full URL, so I added one step and changed the next:
Without filtering, the regex search will fail, because there are lots of protected characters in the URLs.
But now it works great, and it's 4x faster than my dual-loop method—thanks again!