... Continued from here which in turn continues from here

I went about rewriting the duplicate code checker. It works
pretty flawlessly. Even cuts out more stuff than the old
routine, catches a few more things too. (Maybe overlooks some too.)

Code:
alias ddc {
  var %a
  !.echo -q $regsub($1,/(?<=\x03|\x03\d\d\x2C)(\d)(?!\d)/g,0\1, %a)
  while ($regsub(%a, /(?<=\x03\d\d\x2C\d\d|\x03\d\d\x03|\x03)([\x02\x1F\x16\s]+)(\x03(?:\d\d(?:\x2C\d\d)?)?)/g,\2\1, %a)) { }
  !.echo -q $regsub(%a, /(\x02)([\x1F\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x1F)([\x02\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x16)([\x02\x1F\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(?:\x03(?:\d\d(?:\x2C\d\d)?)?)+(\x03(?:(?!\d)|\d\d\x2C\d\d))/g,\1, %a) $&
    $regsub(%a, /(?:\x03\d\d)(\x2C\d\d)(?:\x03\d\d)*(\x03\d\d)/g,\2\1, %a) $&
    $regsub(%a, /(?<=\x03\d\d)(\x2C\d\d)([^\x03]+\x03\d\d)\1/g,\1\2, %a)
  while ($regsub(%a,/(\x03\d\d)((\x2C\d\d)?[^\x03]+)\1/g,\1\2, %a)) { }
  !.echo -q $regsub(%a, /^\x03(?!\d)|(\x03(\d\d(\x2C\d\d)?)?|\x02|\x16|\x1F)+$/g,,%a) $&
    $regsub(%a, /(?<=\x03|\x03\d\d\x2C)0(\d)(?!\d)/g,\1, %a)
  return %a
}


Primarly it works by adding a zero to every one digit color
code. Then, it searches for strings of BURK codes and puts
all the color codes together. Thus all the BUR codes are
together. It kills the dup BUR codes. Then it looks for all color
codes directly before a K with no color arguements or a K
with foreground and background (both would negate the
preceeding colors). Next it looks for color code starting with
a forground/background combo and replaces the foreground
with the last foreground in the color set, and deletes the in
between foreground color sets (no background color sets
exist, as they would remove the preceeding color sets). Next
it looks for background color info ,\d\d after K\d\d followed by
any number of non-color code characters followed by a
color code, with the same background color, and removes
that background color. Which I just noticed isn't optimal,
because "K04,11HiK05ThereK03,11You" is equal
to "K4,11HiK5ThereK3You". But, that regsub won't give me
that. It then looks for single color codes followed by maybe
background color and any number of non color code
characters followed by the original foreground color which is
removed. Done with a while loop, explained shortly. Finally
any blank K codes are removed from the beginning very
beginning, and any color codes (blank or not) and any BUR
codes are removed from the end. And finally any two digit
color code with a zero not directly followed by an additional
digit (messes stuff up) has the zero removed.

There are several issues:
While loop 1: During the sorting routine, attempting to move all
the color codes in a group of BURK color codes to the start
of the codes, it swaps a code that needs to be put later with
a full color code. But, steps beyond that color code. Forcing
the use of the while loop.
While loop 2: To remove duplicate foreground colors with text
between takes, finding a foreground color the text between
and the matched forground color. This steps beyond the
foreground color preventing three same colors with between
text from being removed, hence the while loop to catch them
all.
Background matches with beween color: "K04,11HiK05
ThereK03,11You" is equal to "K4,11HiK5 ThereK3You" alias
fails to fully reduce.
Starting K and Trailing BURK clips: In theory ^ and $ don't
have to be the exact start of a phrase. There could be more
stuff after or before that require that the starting and trailing
code be there. Assumes people use alias to remove BURK
codes from entire lines.
Single digit codes: Frankly, I don't much care, it should work
fine everywhere with mIRC, but I have heard tales that some
poorly coded IRC clients need both codes or they go stupid. I
guess it's not much of an issue gauging how much a market
share badly written clients should have.

PS: Color is \x03. Bold is \x02. Reverse is \x16. Underline is \x1F.