mIRC Home    About    Download    Register    News    Help

Print Thread
#17348 29/03/03 07:10 PM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Code:
alias rdc {
  var %reg = /00[^]*(00)[^,]|01[^]*(01)[^,]|02[^]*(02)[^,]|03[^]*(03)[^,]|04[^]*(04)[^,]|05[^]*(05)[^,]|06[^]*(06)[^,]|07[^]*(07)[^,]|08[^]*(08)[^,]|09[^]*(09)[^,]|10[^]*(10)[^,]|11[^]*(11)[^,]|12[^]*(12)[^,]|13[^]*(13)[^,]|14[^]*(14)[^,]|15[^]*(15)[^,]/g
var %abc
  var %i = $regsub($1,%reg,,%abc)
return %abc
}


The regex works, the problem with the regsub is I can't get it to remove just the matched text. Rather than remove just the dup'ed color code it removes all the other stuff that I used to find the dup color code. The regml's contain the color codes and thus the current code I am forced to use works, but regsub should be able to just remove all the grouped color codes. Also, it seems rather cheap to look for every color and make sure it has no background. But I guess having 256 individual checks would destroy something.

Code:
alias rdc {
  var %reg = /00[^]*(00)[^,]|01[^]*(01)[^,]|02[^]*(02)[^,]|03[^]*(03)[^,]|04[^]*(04)[^,]|05[^]*(05)[^,]|06[^]*(06)[^,]|07[^]*(07)[^,]|08[^]*(08)[^,]|09[^]*(09)[^,]|10[^]*(10)[^,]|11[^]*(11)[^,]|12[^]*(12)[^,]|13[^]*(13)[^,]|14[^]*(14)[^,]|15[^]*(15)[^,]/g
  var %i = $regex($1,%reg), %rt = $1
  while (%i >= 1) {
    %rt = $left(%rt, $calc($regml(%i).pos - 1)) $+ $right(%rt, $calc(($regml(%i).pos + 2) * -1))
    dec %i
  }
  return %rt
}

#17349 29/03/03 10:23 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This what $regsub does by design: it removes the part of the string that matches the regular expression and then replaces it with whatever you have specified in <subtext>. Since you have $null in <subtext> (, $regsub will correctly remove everything. What you actually want is a way to capture the part of the string that you want to keep and put it <subtext>. You already know how to capture stuff with regex: it's the ( ) brackets. What you're missing is the way to put the captured match in <subtext>. This is exactly what \1, \2 do:

Example:
Code:
 //var %a | !.echo -q $regsub(abCDefgh,/[color:red]([/color][A-Z]*[color:red])[/color]/,[color:red]\1[/color],%a) | echo -s %a

The above command looks for capital letters in the input and keeps them, while removing the lowercase ones.
\1 is the first captured match with (), kinda like $regml(1), but with the significant difference that \1 can be used inside the regex pattern itself. To understand its usage a bit more, take a look at this regex, which finds words that are formed by two identical groups of letters (fex "hehe", "haha", "poopoo" etc):

$regex(<input>,/\b([a-z]+)\1\b/i)

According to the above, your %reg variable should be:
Code:
var %reg = /(00[^]*)(00)([^,])|(01[^]*)01([^,])|...

and your $regsub should be: $regsub($1,%reg,\1\2,%a)
What we did is capture every part of the string except the duplicate color. Just because the dupe color is in the middle of the pattern, we need to capture twice, ie the part of the text to the left and right of the dupe color. That's why we also put "\1\2" in <subtext>.

Still, this alias won't catch all cases. For example, if you don't have double digit colors (for colors 0-9), it won't work. You could put a ? right after the leading zero, fex
Code:
/(0?0[^]*)(0?0)([^,])|(0?1[^]*)0?1([^,])|...
? matches 0 or 1 time, so this problem is fixed.

If you want to also catch background colors you don't need 16x16 subpatterns. Just the \d (same as [0-9]) and the ? quantifier. This pattern matches ALL valid dupe colors:
Code:
/(\d\d?(?:,\d\d?)?)[^]*\1/


Continuing our conversation from the previous post, you are right, my alias does what you say. That's because I mainly made it to work having specific combinations in mind (for example your e1 and e2 aliases). "BBHello" isn't supposed to be generated by those aliases. Making a general-purpose alias that minimizes the number of control codes in any given text is not impossible but it can't be done with a single $regsub (can't? well, not sure, but I think it's pretty much impossible). It can be done with more $regsub's though. Here's what I came up with:
Code:
alias mcodes2 {
  var %a
  !.echo -q $&amp;
    $regsub($1,/B((?:[UR]|K(?:\d\d?(?:\x2C\d\d?)?)?)+|)?B/g,\1,%a) $&amp;
    $regsub(%a,/U((?:[BR]|K(?:\d\d?(?:\x2C\d\d?)?)?)+|)?U/g,\1,%a) $&amp;
    $regsub(%a,/R((?:[UB]|K(?:\d\d?(?:\x2C\d\d?)?)?)+|)?R/g,\1,%a) $&amp;
    $regsub(%a,/(?:K(?:\d\d?(?:\x2C\d\d?)?)?)+(K(?:\d\d?(?:\x2C\d\d?)?)?)/g,\1,%a) $&amp;
    $regsub(%a,/(K\d[^K]*K[^K\d][^K]*)K(?=\D|$)/g,\1,%a)
  if $regex(%a,/(K\d)/) { %a = $remove($left(%a,$calc($regml(1).pos - 1)),K) $+ $mid(%a,$regml(1).pos) }
  else %a = $remove(%a,K)
  return %a
}
You should replace B with <ctrl+B>, U with <ctrl+U>, R with <ctrl+R> and K with <ctrl+K>. I left it like that so that the code is more understandable. This one is more thoroughly tested than my previous but it's possible that you'll find a bug. Let me know if you do.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17350 30/03/03 12:48 AM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Seems to work pretty flawlessly.

#17351 30/03/03 01:38 AM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Hmmm, am I missing something or does the originial code still need some extra tweaking. The catch for all dupped color codes works fine, but the replace the sucker properly takes log2(n) times, based off the max number of color codes. With the following sucker.

Code:
  while ($regsub(%a, /(\d\d?(?:,\d\d?)?)([^]*)\1/g,\1\2,%a)) { }

Because to find the dup, it has to also match the dup. Then it replaces the whole set with just the first color and the between text. The problem shows up in that the next match it finds is beyond the second dup. So given three dupped color codes in a row:
K12This K12is K12test

It finds the "K12This K12" replaces "K12This " then goes to the next next char and finds no more repeats in "is K12test"

Hence the while to run through, missing one color code each time and doing it again until there are no more to find. In any case thanks.

Just for posterity sakes:
Code:
alias ddc {
  var %a
  !.echo -q $&amp;
    $regsub($1,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp; 
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp; 
    $regsub(%a,/(?:(?:\d\d?(?:\x2C\d\d?)?)?)+((?:\d\d?(?:\x2C\d\d?)?)?)/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a)
  while ($regsub(%a, /(\d\d?(?:,\d\d?)?)([^]*)\1/g,\1\2,%a)) { }
  if $regex(%a,/(\d)/) { %a = $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos) }  
  else %a = $remove(%a,)
  return %a 
}

#17352 30/03/03 09:33 PM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Drat, apparently to remove the double colors correctly...

while ($regsub(%a, /(\d\d(?:\x2C\d\d)?)([^]*)\1/g,\1\2,%a)) { }

Matching to "K\d\d?" failed because it would match K02 as K0 and then if the next code was K04 it would find the end match of K0 as well and remove the sucker. Not sure how to force it to match the longer one. Maybe (K\d\d|K\d).

#17353 31/03/03 03:35 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The good news is that you can avoid calling $regsub repeatedly if you use lookbehind (and lookahead) assertions. These are non-consuming items, ie the part of the string they match can be re-checked again (if /.../g has been specified, of course).
The bad news is that you still need more than one $regsub calls. This is due to the way lookbehind assertion work (I won't get into details on that, but, if you know what I'm talking about, a pattern like (?<=(K\d\d)|(K\d))([^K]*) can't work). I don't think there's a way of doing this with a single $regsub, but I'd be glad if somebody proved me wrong.

To make your alias work universally, you need to cover all 6 cases of color codes with 6 different $regsub's. An example of these 6 combos is:
1) K03,04<text>
2) K03,4<text>
3) K3,04<text>
4) K3,4<text>
5) K03<text>
6) K3<text>

So, your alias has to be written like:
Code:
alias ddc {
  var %a
  !.echo -q $&amp;
    $regsub($1,/((?:[­]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp;
    $regsub(%a,/­((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?­/g,\1,%a) $&amp; 
    $regsub(%a,/((?:[­]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp; 
    $regsub(%a,/(?:(?:\d\d?(?:\x2C\d\d?)?)?)+((?:\d\d?(?:\x2C\d\d?)?)?)/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    [color:blue]$regsub(%a,/(?&lt;=(\d\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a)[/color]
  if $regex(%a,/(\d)/) { return $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos) } 
  return $remove(%a,) 
}


The alias has grown considerably now but it's still constant-time, in mirc terms. 1000 calls of $ddc() take ~750 msecs average on my Athlon XP 2200+, which is not bad, but I don't know if the delay is negligible when $ddc() is used for processing messages in busy channels for example, especially on slower computers. If you know that the input text is never going to have a single-digit code, you can remove the 2nd, 3rd, 4th and 6th blue line and save some processing time.

Btw, in case you didn't know already, mirc uses the PCRE library for regular expressions, so the most appropriate manual is the PCRE man.txt. Among other things, it fully explains what assertions can (and cannot) do.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17354 31/03/03 12:58 PM
Joined: Feb 2003
Posts: 47
G
Ameglian cow
Offline
Ameglian cow
G
Joined: Feb 2003
Posts: 47
i'd like to help but i'm not sure i understand what you're trying to do smile

i know a bit about regular expressions but not in the way mirc handles them. If you could show some example-input and the desired output then i might be of assistence smile

[edit] Nevermind about the examples, found your previous posting about this :]

Last edited by guesseyder; 31/03/03 01:09 PM.
#17355 31/03/03 05:05 PM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Very nice. Works just as it should. No, I didn't know about the manual, thanks, it's gobs better than the little regex guide I was using.

There is still one small bug, sadly its not an easily caught little case. Rather an oversight.

12,14hey4,34Hello, 12,412,412,4No!

Try that as a test case. Although it seems sound, to remove the second color code as it's quickly reset. The background color is changed and without the alias the background for the Hello is green (3) while with the other code its grey (14). I didn't even realize color codes worked like that. Oh, and pasting all that code you had had even odder errors. For that test case it returned: 4hey H e l l o , 12,4No!.

In any case, thanks for all your help.

Code:
alias ddc {
  var %a
  !.echo -q $&amp;
    $regsub($1,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp; 
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|\s)?/g,\1,%a) $&amp; 
    $regsub(%a,/(?:(?:\d\d?(?:\x2C\d\d?)?)?)+(\s*(?:\d\d?(?:\x2C\d\d?)?)?)/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a)
  ;!.echo -q $regsub(%a, /(?&lt;=:(\d\d(?:\x2C\d\d)?)([^]*))\1/g,\1\2,%a);ignore
  if $regex(%a,/(\d)/) { %a = $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos) }  
  else %a = $remove(%a,)
  return %a
}

#17356 31/03/03 08:38 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Bah, there was a typo in the ddc I pasted in my last post. Probably because, to test it, I used "K" instead of <ctrl+K>, then I used Find&Replace to replace the K's with <ctrl+K>. Somewhere along the way I screwed up. Here's the alias that works as I originally wanted (I also fixed a bug in it, saw it just now):
Code:
alias ddc {
  var %a
  !.echo -q $&amp;
    $regsub($1,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/(?:(?:\d\d?(?:\x2C\d\d?)?)?)+((?:\d\d?(?:\x2C\d\d?)?)?)/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))(\x2C|(?:\x2C\D|[^\x2C])[^]*)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))(\x2C|(?:\x2C\D|[^\x2C\d])[^]*)\1(?!\d)/g,\2,%a)
  if $regex(%a,/(\d)/) { return $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos) }
  return $remove(%a,)
}


However, it has the problem you mentioned, as I didn't know about this behaviour either (that bg colouring is kept when the next color code doesn't specify a bg colour). The following version of the alias (hopefully) deals with it (by adding one more $regsub call):
Code:
alias ddc {
  var %a
  !.echo -q $&amp;
    $regsub($1,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/((?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)+|)?/g,\1,%a) $&amp;
    $regsub(%a,/(?:\d\d?(\x2C\d\d?|))+(\d\d?)(\x2C\d\d?|)/g,\2\1\3,%a) $&amp;
    $regsub(%a,/(?:\x2C\d\d?)?(\x2C\d\d?)|(\x2C\d\d?|)/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d\d))([^]+)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\x2C\d))([^\d]+[^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))(\x2C|(?:\x2C\D|[^\x2C])[^]*)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))(\x2C|(?:\x2C\D|[^\x2C\d])[^]*)\1(?!\d)/g,\2,%a)
  if $regex(%a,/(\d)/) { return $remove($left(%a,$calc($regml(1).pos - 1)),) $+ $mid(%a,$regml(1).pos) }
  return $remove(%a,)
}


Edit: Another typo :tongue:


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17357 03/04/03 04:02 AM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
1212,14503hey4,34Hello, 12,412,412,4No!

Fails.

This alias has taken like a zillion more lines than initial it was suppose to. I guess the bg check just needs some expanding. Not that it's even an issue, I don't think the sheer majority of things this sucker checks for are even going to be used in what I am using it for. Just got sortof carried away making the sucker all purpose.


#17358 03/04/03 05:26 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Yep, it fails. I've been improving the alias since my last post and found a few bugs. I think that, this time, it works correctly (I've tested it far more extensively than any previous version, with every combination I could think of). Here it is:
Code:
alias ddc {
  var %a = $1
  !.echo -q $&amp;
    $regsub(%a,/(?:\d\d?(\x2C\d\d?)?)+(?(1)|())(\d\d?)(\x2C\d\d?|)/g,$+(\2,$cr,\1,$lf,\3,$lf),%a) $&amp;
    $regsub(%a,/\r(?:\x2C\d\d?)?\n(\x2C\d\d?)\n|\r(\x2C\d\d?|)\n\n/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))(\x2C(?:[^\d][^]*)?|[^\x2C][^]*)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))(\x2C(?:[^\d][^]*)?|[^\x2C\d][^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/\d\d?(\x2C\d\d?)?(?!\d)/g,,%a)
  !.echo -q $&amp;
    $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) $&amp;
    $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) $&amp;
    $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,)
}
This time it has 13 $regsub's, let's hope it's the lucky number :tongue:


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17359 03/04/03 12:52 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Damn, another typo: control codes in the wrong place. All control codes look the same (a square) so I keep making typos of the type BU instead of BR and never notice them. Sucks.
Code:
alias ddc {
  var %a = $1
  !.echo -q $&amp;
    $regsub(%a,/(?:\d\d?(\x2C\d\d?)?)+(?(1)|())(\d\d?)(\x2C\d\d?|)/g,$+(\2,$cr,\1,$lf,\3,$lf),%a) $&amp;
    $regsub(%a,/\r(?:\x2C\d\d?)?\n(\x2C\d\d?)\n|\r(\x2C\d\d?|)\n\n/g,\1,%a) $&amp;
    $regsub(%a,/(\d[^]*[^\d][^]*)(?=\D|$)/g,\1,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d)(\x2C\d\d))([^]+)\1\2?/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d)(\x2C\d))([^\d][^]*)\1\2?(?!\d)/g,\3,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d\d))(\x2C(?:[^\d][^]*)?|[^\x2C][^]*)\1/g,\2,%a) $&amp;
    $regsub(%a,/(?&lt;=(\d))(\x2C(?:[^\d][^]*)?|[^\x2C\d][^]*)\1(?!\d)/g,\2,%a) $&amp;
    $regsub(%a,/\d\d?(\x2C\d\d?)?(?!\d)/g,,%a)
  !.echo -q $&amp;
    $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) $&amp;
    $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) $&amp;
    $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,)
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17360 05/04/03 09:48 AM
Joined: Dec 2002
Posts: 17
C
Pikka bird
Offline
Pikka bird
C
Joined: Dec 2002
Posts: 17
What was all this code for again? I forgot LOL
Is it just to remove redundant color codes (codes that don't affect any text)?

#17361 05/04/03 12:41 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Exactly. It converts a string like this:
BBURUUBRone K4,3K5two K6,7three K6,7four K6,7five
into this:
UBone K5,3two K6,7three four five

making sure it doesn't convert this:
BKB4,3one
to this:
K4,3one

or this:
K1one K12two
to this:
K1one 2two

(B,U,R,K are the bold,underline,reverse and colour codes)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard