mIRC Home    About    Download    Register    News    Help

Topic Options
#180252 - 06/07/07 05:19 PM $regsub help
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Hi,
I tried some hours here and there to find a working way to "highlight" the matching parts of a %wildcard.mask in a $fulladdress (nick!ident@host.domain)
I sampled (and failed) cycling the parts nick ident host with $mid $len $pos and the like...
$regsub seems to be the most promising approach.

I managed (trial and error, to be honest) simple replaces like:
Code:
//var %test | noop $regsub(teststring,/s.+in/gi,8s*in,%test) |  echo -a %test
or
Code:
//var %text = some!test@string | echo -a $regsubex(%text,/(ome.*!.*st)/gi,$+($chr(3),07\t,$chr(15)))

... but in fact, I am quite green with $regsub, therefore I need some skilled help smile


The goal is to visualize the matching parts of a "full" %wildcard.mask (not an shortened *@host.domain or the like, maybe thats important for error handling) in some $fulladdress in two ways:
1) highlight matching "text" in some colour 1
2) highlight "text met by wildcards" in some other colour 2

e.g.: to make the parts of "nic*!user@*.doma*n" in "nick!user@host.domain" become: "nick!user@host.domain"

Some problems I anticipate are:

a)
[can be resolved by a simple $replace in the beginning, but maybe this gotta be done in the $regsub somewhere, too]
Escape possible metachars [ ] { } ^ | \ . * (which may be part of addresses and banmasks) with \[ \] \{ \} \^ \| \\ \. .*

b)
Stop regex comparison at ! and @ - as wildcards in masks like banmasks stop there, too

c)
If a part of the $fulladdress is already "met" (coloured) by a wilcard, but met exactly by more parts of the %wildcard.mask, the exact match shall have priority.
e.g.:

A highlighting of "A-test-nick!apple@pie" compared to "*t*!tomato@*"

shall higlight as:
A-test-nick!apple@pie

and not as:
A-test-nick!apple@pie

Thoughts:
I played with separating the $fulladdress and %wildcard.mask into its components (nick-user-host) to avoid b)
There is also no need to make the $regsub as neat or short as possible, working code is what really counts smile


Thx a lot in advance!

Top
#180259 - 06/07/07 07:09 PM Re: $regsub help [Re: Horstl]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Here's a relatively simple alias that (hopefully) satisfies all your conditions except (c):
Code:
alias wildcolor {
  var %2 = $2, %c1 = 03, %c2 = 04
  tokenize 64 $1
  var %host = $2, %nick = $gettok($1,1,33), %user = $gettok($1,2,33)
  tokenize 64 $replace(%2,\,\\,^,\^,$,\$,.,\.,[,\[,|,\|,+,\+,$chr(123),\ $+ $chr(123),?,(.),*,(.*?)) 
  var %a = $regex(a,%host,$+(/^,$2,$!/i)), $& 
    %b = $regex(b,%nick,$+(/^,$gettok($1,1,33),$!/i)), $&
    %c = $regex(c,%user,$+(/^,$gettok($1,2,33),$!/i))
  tokenize 64 %2
  if (%a) %host = $+(,%c2,$regsubex($2,/[*?]/g,$+(,%c1,$regml(a,\n),,%c2)),)
  if (%b) %nick = $+(,%c2,$regsubex($gettok($1,1,33),/[*?]/g,$+(,%c1,$regml(b,\n),,%c2)),)
  if (%c) %user = $+(,%c2,$regsubex($gettok($1,2,33),/[*?]/g,$+(,%c1,$regml(c,\n),,%c2)),)
  return $replace($+(%nick,!,%user,@,%host),$+(,%c1,),,$+(,%c2,),)
}
Usage is $wildcolor(full address, wildcard mask). You can change %c1 and %c2 at the top with whatever colour codes you want (just make sure they are zeropadded).

Regarding (c), I'm not sure I get the logic or the exact way it's intended to work, but it looks like it can't be easily incorporated to this alias. If you explain it a little more, I (or others) may be able to help.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#180265 - 06/07/07 08:43 PM Re: $regsub help [Re: Horstl]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
First off, I have to say: whow... and thanks, qwerty! smile

c) was intended as - how to put it - "greedy highlighting"...

eg.:
"*oo*" will match "yooyoo" two times, > mark both occurances of "oo"
"test" will match "test-the-test" 2 times...
"te?t" will match "test-tea-test" 2 times, too... but "te*t" matches "test-tea-test" a LOT more ...

... well, now I start to realize that this might get quite complicated - Most likely, the effort needed will not warrant the result.
The output could even look confusing ....Thinking it over again, I hold that maybe it's a good idea to discard that c) -idea.
And, in fact, the code you provided does the job perfectly: Highlighting if, and where parts of a fullmask are matched by a wildcard mask.
Highlight ALL possible matches is of doubtful usage for my purpose. (I wonder how this could be done, nevertheless) wink

Thanks.

Top
#180267 - 06/07/07 09:20 PM Re: $regsub help [Re: qwerty]
OrionsBelt Offline
Fjord artisan

Registered: 25/04/06
Posts: 464
Loc: Amsterdam, NL
Originally Posted By: qwerty
Here's a relatively simple alias...


Yeah right!

Top
#180269 - 06/07/07 09:30 PM Re: $regsub help [Re: Horstl]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
OK I get (c) now, however I'm afraid it can't be incorporated to the existing code. To implement (c) you'd probably have to script a wildcard matching routine from scratch. It would have to be exhaustive, trying all substrings that can be matched by each * char (a recursive approach would be most natural here). You can find examples of recursive wildcard matching algorithms on the net to get an idea, but I wouldn't bother if I were you. Scripting that would be neither simple nor fast.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#180290 - 07/07/07 08:15 AM Re: $regsub help [Re: Horstl]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Hum, think I'll keep my hands off that wink
I learned a lot meditating about your code, albeit I'd hardly be able to do it in such a way. Thx again.

Top