Hello Everyone,
Ok I have a list of numbers separated by a semi-colon. Such as:
i.e. 1;2;3;4;5;6;7;8;9;1;2;3;23;34;51;
In the above list 1;2;3; repeats. The following RegEx removes repeats.
RegEx>\b(\d\d?);(?!.*\b\1\b),StringInQuestion,0,match,NumbersExcluded,1,,RepeatsRemoved
This results in:
i.e. 4;5;6;7;8;9;1;2;3;23;34;51;
The 1;2;3; At the beginning was removed. But, and this is where I need some help, 1;2;3; still remains in the string.
I want both instances of any numbers that repeat to be removed. So the desired result would be:
i.e. 4;5;6;7;8;9;23;34;51;
Both instances of 1;2;3; have been removed in the last above example.
How could I accomplish this with RegEx?
RegEx Help, Please
Moderators: Dorian (MJT support), JRL
RegEx Help, Please
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
- Grovkillen
- Automation Wizard
- Posts: 1062
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: RegEx Help, Please
Single RegEx will probably not do exactly what you want (memory for pulling of that one might be big?). This is how I would do it:
I put the semi colon in the beginning of the string to simplify the replacement of the duplicates.
Since this one will match all duplicates, your loop will be iterated more times than needed, you could have a variable that stored already removed duplicates and thus speed the loop up.
Code: Select all
Let>STRING=;1;2;3;4;5;6;7;8;9;1;2;3;23;34;51;
Let>REGEX_PATTERN=\b(\d+)\b(?=.*\b\1\b)
RegEx>REGEX_PATTERN,STRING,0,FOUND,FOUND_count,0,,
If>FOUND_count>0
Let>k=0
Repeat>k
Let>k=k+1
Let>TEMP_to_be_removed=FOUND_%k%
StringReplace>STRING,;%TEMP_to_be_removed%;,;,STRING
Until>k=FOUND_count
Endif>
Since this one will match all duplicates, your loop will be iterated more times than needed, you could have a variable that stored already removed duplicates and thus speed the loop up.