mIRC Home    About    Download    Register    News    Help

Print Thread
optimize a $regex #72183 20/02/04 06:14 PM
Joined: Feb 2004
Posts: 14
H
hatten Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Feb 2004
Posts: 14
check {

unset %result

var %match = $regex($1,/(footext.1|footext.2|footext.3)/i)
if %match >= 1 {
set %result 1
}
}
ok this works, but is there any way I can skip the if %match >= 1 part to make the alias look more efficient ?

tnx

Re: optimize a $regex #72184 20/02/04 06:46 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
- You can remove the %match variable altogether and just make it the comparison, the '>= 1' isn't required since the result will automatically be treated as true if it's a non-zero result.
- If there's only one line to be run if the condition is true then you can put that on the same line and remove the braces ({ }) aswell.
- Your regex can be simplified to /(footext.(?:1|2|3))/i if you wanted.
Code:
check {
unset %result
if ($regex($1,/(footext.(?:1|2|3))/i)) set %result 1
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: optimize a $regex #72185 20/02/04 07:14 PM
Joined: Feb 2004
Posts: 14
H
hatten Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Feb 2004
Posts: 14
quality reply.

tnx a lot smile

Re: optimize a $regex #72186 20/02/04 07:28 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Or if the %result doesn't need to be only 0 or 1 but 0 or <any non-zero number>, one could do:
Code:
alias check %result = $regex($1,/(footext.[123])/i)
Btw, I optimized the regex a bit.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: optimize a $regex #72187 20/02/04 11:03 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Ahh yes, for some reason I was thinking that an unset variable was different from one with a zero value, but I guess with the exception of $var() it's the same thing in mIRC.

Thanks for pointing out the regex, I hadn't even noticed it could be a character set.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: optimize a $regex #72188 21/02/04 11:26 AM
Joined: Feb 2004
Posts: 14
H
hatten Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Feb 2004
Posts: 14
ok thanks again for this great help. I have another rather ugly if which uses !isin + &&. looks like this;

negcheck {
if ($1 !isin %variable1) && ($1 !isin %variable2) && ($1 !isin %variable3) && ($1 !isin %variable4) && ($1 !isin %variable5) && ($1 !isin %variable6) && ($1 !isin %variable7) && ($1 !isin %variable8) && ($1 !isin %variable9) && ($1 !isin %variable10) {
echo -s yadda yadda
}
}

How do I make that a lovely looking $regex ?


Re: optimize a $regex #72189 21/02/04 11:34 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
not a regex but hey

negcheck {
if ($1 !isin %variable1 %variable2 %variable3 %variable4 %variable5 %variable6 %variable7 %variable8 %variable9 %variable10) { echo -s yadda yadda }
}

$1 cant be in any of them , so there fore it cant be in any of them when there put together.

Re: optimize a $regex #72190 21/02/04 11:40 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
negcheck return $iif($1 !isin %variable1 %variable2 %variable3 %variable4 %variable5 %variable6 %variable7 %variable8 %variable9 %variable10, 1, 0)


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: optimize a $regex #72191 21/02/04 12:42 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Hmm... bit of an awkward one this. Technically, what you have already is probably the fastest way to do it with 100% accuracy.

DaveC's will work, however, it requires that $1 doesn't ever have a space in it otherwise it could break a lot.

Here's my version of it, it simply requires that there isn't a linefeed (newline character) inside any of the variables or $1, which isn't impossible, but very very unlikely.
Code:
negcheck {
  var %toks = $+(%variable1,$lf,%variable2,$lf,%variable3,$lf,%variable4,$lf,%variable5,$lf)
  %toks = $+(%toks,%variable6,$lf,%variable7,$lf,%variable8,$lf,%variable9,$lf,%variable10)
  if (!$wildtok(%toks, $+(*,$1,*), 0, 10)) { echo -s yadda yadda }
}

It could also be done with $regex instead of $wildtok but it's a little bit slower so I didn't show that one.

If you want to check every variable with a name starting '%variable' then you can use this:
Code:
negcheck {
  var %i = 1
  while $var(%variable*, %i).value != $null {
    if ($1 isin $ifmatch) return
    inc %i
  }
  echo -s yadda yadda
}

This one will also work no matter what $1 or the variables contain, however it's about half the speed of the others.


Spelling mistakes, grammatical errors, and stupid comments are intentional.