Reputation: 1
I have a bit of a problem trying to remove duplicate strings in regex. Here are some example strings, followed by my code and then followed by what im getting vs what I want.
Examples
Test1; Test3; Test3; Test12
Test3; Test3
My code
\b(\w+); (?=.*\b\1;?) replaceing with blanks
Gives me
Test3; Test12
Test3
I want
Test1; Test3; Test12
Test3
Any help would be greatly appreciated!
Thanks
Upvotes: 0
Views: 63
Reputation: 336158
Your problem is that Test1
also matches part of Test12
. You already used word boundary anchors, just not in all the necessary spots:
\b(\w+)\b; (?=.*\b\1\b)
Test it live on regex101.com.
Upvotes: 1