mIRC Home    About    Download    Register    News    Help

Print Thread
Wildcards and $chr(42) #148188 01/05/06 03:59 AM
Joined: Feb 2005
Posts: 9
K
Kaepez Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Feb 2005
Posts: 9
I'm trying to get something working that will echo a message whenever the user types a message beginning with an asterisk. I tried using $chr(42) with an "on INPUT" and an if conditional, but unless something else was messed up, mirc treated "$chr(42)*" as a double wildcard, which was definitely not the intended effect.

Can I get a little help? Thanks.

Re: Wildcards and $chr(42) #148189 01/05/06 04:12 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
  if ($str($chr(42),2) iswm $1) echo -a $v2
  if ($left($1-,1) == *) echo -a $1-


-Andy

Re: Wildcards and $chr(42) #148190 01/05/06 04:14 AM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
try this
Code:
on *:input:*:{
  if ($mid($$1,1,1) == $chr(42)) {
    echo -a You typed a $chr(42)
  }
}

Re: Wildcards and $chr(42) #148191 02/05/06 06:44 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
on *:input:*: if ($regex($1,/^\*/)) { echo -a You typed a * }


$maybe
Re: Wildcards and $chr(42) #148192 02/05/06 09:43 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
You know what i think would be great
If when those of you who use and understand regex (or even other advanced coding) include a detailed explanation (for those of us who got headaches after trying to read the help online for regex) so others might benefit from the example you give with info on what it all means.

Re: Wildcards and $chr(42) #148193 02/05/06 10:35 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Your absolutely right my post had little to contribute other then a few bytes saved.

on *:input:*: if ($regex($1,/^\*/)) { echo -a You typed a * }

$regex returns the total matches so the if statement will be false if it doesn't find any since 0 is false.

regular expressions are enclosed in a pair of / so the actual expression is ^\*
^
means the start of the string
\*
since * is a special character to quantify a character zero or more times it needs to be escaped so it loses it special meaning and becomes the litural *
so ^\* means if the string ($1- in this case) starts with a * then return true.

Quantifiers:
*: $regex(a,ab*) returns true because a is followed by zero or more b characters.
The other quantifier is +: which means 1 or more
so
$regex(a,ab+) is false because a isn't followed by one or more b's


$maybe
Re: Wildcards and $chr(42) #148194 03/05/06 12:51 AM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:
[color:blue] starting delimiter / [/color][color:red] Start of expression (string) ^ [/color][color:green]Escape Character (required due to special regex meaning for * in this case) \ [/color] the character to test for * [/color][color:blue] End delimiter /[/color]

though I think the OP wanted to check the first character of the first word only (or did I miss something) but the regex would match 1 or more * in the string (did i read that right?)

Re: Wildcards and $chr(42) #148195 03/05/06 12:59 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
I tested the code and it returns.

0 for test
1 for *test
1 for *test*

So I guess it does match the first caharacter of the first word. smile

-Andy

Re: Wildcards and $chr(42) #148196 03/05/06 07:24 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
since we escaped * it has lost its special meaning and is just a litteral * so the regex says:

start of the string followed by an *.
"*hello you!" is true
"hello *you!" is false because the first character in the string is an "h".


$maybe
Re: Wildcards and $chr(42) #148197 03/05/06 09:42 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
ok so what threw me was
Quote:

on *:input:*: if ($regex($1,/^\*/)) { echo -a You typed a * }

$regex returns the total matches so the if statement will be false if it doesn't find any since 0 is false.


in this case the coding of the regex didnt specify any/all matches, so it checked only the first character in the string (which in this case because only $1 too, not $1-), while $regex() would return any/all matches if it was coded a bit different.... right?

Re: Wildcards and $chr(42) #148198 03/05/06 11:18 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
$regex will only return all matches if the /g modifier is specified. In absence of it, it immediately returns on matching (or no matching), meaning it will either evaluate to 0 or 1.

Heh, once I had plans to write the "ultimate regex tutorial" named the "Regex Bible", but then I got a fulltime job and everything changed. mIRC is just a memory now :tongue:

Oh well, happy scripting to all smile


Gone.
Re: Wildcards and $chr(42) #148199 04/05/06 07:11 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
true but even if the g modifier was specified theres always only one start of the string :P

And about your bible i still think you should do a tips & tricks tutorial frown Your posts are missed FO frown


$maybe