Given this haystack and Regex PCRE2(PHP>=7.3):
#1 #2 #3
green [foo] [foo1]
red [foo]
blue [foo] [foo1] [foo2]
yellow [foo2]
green [foo]
green [foo] [foo1]
red [foo]
pink [foo3]
Where:
#1 is always a string that can contain numbers but no spaces.
#2 is always a random amount of space between #1 and 3.
#3 same as #1 but inside of brackets [ ] and can exist multiple brackets.
I'm trying to remove all lines containing dupes on #1 but keeping the last dupe line found.
It would look like:
blue [foo] [foo1] [foo2]
yellow [foo2]
green [foo] [foo1]
red [foo]
pink [foo3]
Cleared all lines that contain the same string on #1 keeping only the last.
And the lines that don't contain dupes on #1 as for example:
pink [foo3] keep them.
I tried to explain it in the most detail possible, let me know if it is still unclear or if it's not possible with regex.