mIRC Home    About    Download    Register    News    Help

Print Thread
#81627 02/05/04 02:58 AM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
how to use $regex for these if else statements? basically to make sure there are no simbols either than # in channel name and server name.

Code:
on *:dialog:join.edit:sclick:1: {
  if (%join.chan == $null) || (%join.net == $null) { 
    dll $_hdll Error Error Message > You left a field empty. | halt 
  }
  elseif (*#* !iswm %join.chan) { 
    dll $_hdll Error Error Message > Channel name must have '#' | halt 
  }
  elseif (*#* iswm %join.net) || (*;* iswm %join.net) || (*$* iswm %join.net) || (*^* iswm %join.net) || (*&* iswm %join.net) { 
    dll $_hdll Error Error Message > Can't add simbols in Network name. $chr(40) $+ %join.net $+ $chr(41) | halt 
  }
  else { 
    write -l %join.edit $auto_txt %join.chan $+ $chr(149) $+ %join.net $+ $chr(149) $+ %join.delay
    join.unset
  }
  auto_load
}

#81628 02/05/04 03:29 AM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
Try this:
replace the (*#* iswm %join.net) || (*;* iswm %join.net) || (*$* iswm %join.net) || (*^* iswm %join.net) || (*&* iswm %join.net)

with this...
Code:
if ($regex(%join.net,/(\#|;|\$|\^|\&)/g)) { echo Invalid symbols }


I'm still learning RE's but I *THINK* that should work.

Obviously, replace what's inbetween the {}'s with what you really want it to do.

grin

#81629 02/05/04 12:24 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

you can replace this:
Code:

elseif (*#* iswm %join.net) || (*;* iswm %join.net) || (*$* iswm %join.net) || (*^* iswm %join.net) || (*&* iswm %join.net) 

with this:
Code:

elseif $regex(%join.net,/[#$&^;]/) { ... 


To Wolfie: it's not needed to use /g as the regex would continue looking in the string even when matched already (it goes through the whole string trying to find as many matches as possible), while 1 invalid character is already enough to stop the script.
Also it's not needed to capture the characters #$&^; because we only wanna know if theyre in there, without having to know what they are.

But like you, I'm very new to $regex, $regsub, and $regml, so we're all still learning smile

Greetz


Gone.
#81630 02/05/04 05:08 PM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
* smacks self *

I forgot about the [ ]'s.. And I'm used to the /g since when I use it, I want all the results.. oops. Thanks for the info dude.
cool

#81631 02/05/04 05:42 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hehe,

you're welcome!

Greetz


Gone.
#81632 03/05/04 02:31 AM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
Code:
elseif $regex(%join.net,/[#$&^;]/) { <error msg> }


this did not work frown

#81633 03/05/04 02:45 AM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
nevermind it works :P


Link Copied to Clipboard