$regsub matching to remove duplicate color codes. - 05/04/03 10:20 PM
... Continued from previous posting.
The following alias removes almost flawlessly duplicate color codes from any text given to it.
The almost flawlessly is based on the fact that:
11,2031234 this bugger's broke a little more.
Fails to work properly. It's not that sevear seeing as I actually spent time to think up something that would break it. But, basicly I think it needs a quick addition to delete one digit color codes.
I think:
$regsub(%a, /(\d)([^\d])/,0\1\2, %a)
$regsub(%a,/(\d\d?\x2C)(\d)([^\d])/, \10\2\3, %a)
will catch and kill single color color codes. Actually making a few lines in the alias unneeded.
Just tested, and I'm wrong. Also needs to check all the way back to the front.
Also perhaps the color codes should all be converted to hex. is hard to tell from , but \x03 is easy to tell from \x02 not that the readablity is that high to begin with.
[code]
alias ddc {
var %a = $1
!.echo -q $&
$regsub(%a,/(?:\d\d?(\x2C\d\d?)?)+(?(1)|())(\d\d?)(\x2C\d\d?|)/g,$+(\2,$cr,\1,$lf,\3,$lf),%a) $&
$regsub(%a,/\r(?:\x2C\d\d?)?\n(\x2C\d\d?)\n|\r(\x2C\d\d?|)\n\n/g,\1,%a) $&
$regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&
$regsub(%a,/(?<=(\d\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&
$regsub(%a,/(?<=(\d\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&
$regsub(%a,/(?<=(\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&
$regsub(%a,/(?<=(\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&
$regsub(%a,/(?<=(\d\d))(\x2C(?:[^\d][^]*)?|[^\x2C][^]*)\1/g,\2,%a) $&
$regsub(%a,/(?<=(\d))(\x2C(?:[^\d][^]*)?|[^\x2C\d][^]*)\1(?!\d)/g,\2,%a) $&
$regsub(%a,/\d\d?(\x2C\d\d?)?(?!\d)/g,,%a)
!.echo -q $&
$regsub(%a,/(^|(?:(?:(?:(?:[^]\d|[^\D])\d|\D)\x2C|[^\x2C])\d|[^\d\x2C]))(?=\d)|(^|(?:\d\d?(?:\x2C\d\d?)?)?)(?!\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*[])(?=\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+)(?!\d)/g,\1,%a) $&
$regsub(%a,/(^|(?:(?:(?:(?:[^]\d|[^\D])\d|\D)\x2C|[^\x2C])\d|[^\d\x2C]))(?=\d)|(^|(?:\d\d?(?:\x2C\d\d?)?)?)(?!\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*[])(?=\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+)(?!\d)/g,\1,%a) $&
$regsub(%a,/(^|(?:(?:(?:(?:[^]\d|[^\D])\d|\D)\x2C|[^\x2C])\d|[^\d\x2C]))(?=\d)|(^|(?:\d\d?(?:\x2C\d\d?)?)?)(?!\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*[])(?=\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+)(?!\d)/g,\1,%a)
if $regex(%a,/(\d)/) {
return $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos)
}
return $remove(%a,)
}
[\code]
The following alias removes almost flawlessly duplicate color codes from any text given to it.
The almost flawlessly is based on the fact that:
11,2031234 this bugger's broke a little more.
Fails to work properly. It's not that sevear seeing as I actually spent time to think up something that would break it. But, basicly I think it needs a quick addition to delete one digit color codes.
I think:
$regsub(%a, /(\d)([^\d])/,0\1\2, %a)
$regsub(%a,/(\d\d?\x2C)(\d)([^\d])/, \10\2\3, %a)
will catch and kill single color color codes. Actually making a few lines in the alias unneeded.
Just tested, and I'm wrong. Also needs to check all the way back to the front.
Also perhaps the color codes should all be converted to hex. is hard to tell from , but \x03 is easy to tell from \x02 not that the readablity is that high to begin with.
[code]
alias ddc {
var %a = $1
!.echo -q $&
$regsub(%a,/(?:\d\d?(\x2C\d\d?)?)+(?(1)|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\d\x2C]))(?=\d)|(^|(?:\d\d?(?:\x2C\d\d?)?)?)(?!\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*[])(?=\d)|((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+)(?!\d)/g,\1,%a)
if $regex(%a,/(\d)/) {
return $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos)
}
return $remove(%a,)
}
[\code]