|
Joined: Feb 2005
Posts: 9
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
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.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
if ($str($chr(42),2) iswm $1) echo -a $v2
if ($left($1-,1) == *) echo -a $1-
-Andy
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
try this
on *:input:*:{
if ($mid($$1,1,1) == $chr(42)) {
echo -a You typed a $chr(42)
}
}
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 759 |
on *:input:*: if ($regex($1,/^\*/)) { echo -a You typed a * }
$maybe
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
[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?)
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
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. -Andy
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
ok so what threw me was 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?
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
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
Gone.
|
|
|
|
Joined: Apr 2004
Posts: 759
Hoopy frood
|
Hoopy frood
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 Your posts are missed FO
$maybe
|
|
|
|
|