mIRC Home    About    Download    Register    News    Help

Print Thread
if statement help #62417 30/11/03 08:23 PM
Joined: Apr 2003
Posts: 24
S
ShavedApe Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 24
I am having a little trouble whith the if statement.
What i need to do is check a line of text for a bad word then act upon it.
Now that bit I can do but and heres where I have the problem.
It also sees words that contain my bad word as being what I look for so for eg.

if (ape isin $1) { some action }

now the line of text contains the word ape and the action is performed.
If the line of text was to contain say for ease shavedape the action is still performed.
Is there a way to make the if statement more specific.

Please bear in mind I use ape and shavedape purely as an example this is for a much larger scale than checking for my nick.

Re: if statement help #62418 30/11/03 08:27 PM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
if ( $istok($1-,ape,32) ) { dostuff }

Re: if statement help #62419 30/11/03 09:41 PM
Joined: Dec 2002
Posts: 1,922
O
Online Offline
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
A simple (yet powerful) swear kicker that uses regular expression match:
  • On @$*:text:/(word1|word2|word3)/Si:#channel:ban -ku300 # $nick 2 Language: $regml(1)
You can add as many words as you want inside the parentheses separated by |.

Whenever you want a word not to match partial words in the said sentence, put it inside a pair of \b. For example, \b[color:blue]ape\b[/color].

Due to the way regex works, there are some reserved characters which you'll have to escape so they will be treated as literal letters. For example, ? * . + [ ] { } \ ^ $ ( ) | will be changed to \? \* \. \+ \[ \] \{ \} \\ \^ \$ \( \) \| respectively.

Regex tutorial #1
Regex tutorial #2
PCRE manual

Re: if statement help #62420 30/11/03 10:09 PM
Joined: Apr 2003
Posts: 24
S
ShavedApe Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Apr 2003
Posts: 24
Thanks for the quick reply much appreciated and now my script works so laugh

Re: if statement help #62421 01/12/03 11:38 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Too bad \b recognizes latin chars such as , , etc. as word boundaries as well =(.. a special char excluding them could save some time. Edit: well not only \b though, regex itself doesn't consider them word chars.

Last edited by cold; 01/12/03 11:40 PM.

* cold edits his posts 24/7
Re: if statement help #62422 01/12/03 11:49 PM
Joined: Dec 2002
Posts: 1,922
O
Online Offline
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
The \b's can be changed to lookbehind and lookahead assentions, (?<=\s|^) and (?=\s|$)

Re: if statement help #62423 01/12/03 11:56 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
I know, but that would cover only spaces, beginning and ending, dropping punctuations and the like. Some functionality is missed, for example, in a regex matchtext for an event, where you can't use [[:punct:]] the normal way.
Then again I know it would be solved with a simple ranged character class, but I'd really like to have this set as nicely as a simple \b.

Last edited by cold; 02/12/03 12:00 AM.

* cold edits his posts 24/7