Nice catch, here is a simple fix:
//echo -a $regsubex(Nickname1 Nickname3 NickName2 Nickname2 Nickname1,/(?<=\G| )([^ ]+) (?=(?:\1|.* \1)(?: |$))/gSi,)
@Simo: you're replacing the match with a space, but we're trying to get rid of extra space when deleting a word, not add more, it was deleting a space incorrectly because the first part (?:\G| ) consume the space incorrectly on the left of the word, by making this part a positive lookbehind, it's no longer consumed. Note that it's possible to deal with this with a sexy \K as well
//echo -a $regsubex(Nickname1 Nickname3 NickName2 Nickname2 Nickname1,/(?:\G| )\K([^ ]+) (?=(?:\1|.* \1)(?: |$))/gSi,)
In fact this \K technique is required with PCRE, had OP's requirement be to match non fixed length stuff.
Last edited by Wims; 05/05/24 05:32 PM.