mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2005
Posts: 28
T
Tuxman Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Dec 2005
Posts: 28
I want to check an ON INPUT string for the /server command in order to filter out the password.

According to the PCRE specifications I would have to execute this expression:

/\d{3,5} (\S+)/

Now mIRC does not know this.

Code:
on *:input:*:{
  if ($left($1,7) == $readini($mircini,text,commandchar) $+ server) {
    echo $regex($1-, /\d{3,5} (\S+)/)
  }
}


echoes 0.

Code:
on *:input:*:{
  if ($left($1,7) == $readini($mircini,text,commandchar) $+ server) {
    echo $regex($1-, /\d\d\d+ (\S+)/)
  }
}


echoes 1.

I am pretty sure this is wrong.


Gamers.IRC team - gamersirc.net
#Gamers.IRC on QuakeNet (sometimes we're there).
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Your problem is the presence of a comma in the regular expression. Since mIRC does not use quotes around strings it is unable to distinguish a comma meant for the regular expression from one meant to separate two parameters to $regex(). The fix is simple: assign the regular expression to a variable and use that in the $regex() call.

Code:
var %re = /\d{3,5} (\S+)/
echo $regex($1-, %re)


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2005
Posts: 28
T
Tuxman Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Dec 2005
Posts: 28
Well, thank you! :-)

This does not invalidate my bug report though. At least it should be documented properly.


Gamers.IRC team - gamersirc.net
#Gamers.IRC on QuakeNet (sometimes we're there).
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Although I agree that good documentation is needed for any program, keep in mind that this is how the scripting engine works with regard to all identifiers (the same is true for spaces in commands). The note about commas could be placed in every identifier, but that is kind of excessive. Most of the time, people are learning scripting from very basic commands that also have to properly handle comma use, so by the time they reach something as complex as regular expressions, they already know that commas are special in mIRC.

For example, you couldn't do something like:

//echo -a $gettok(hey, what's up?,1,32)

And for spaces, you couldn't do something like:

//write this is a long filename.txt hello

In both cases, the delimiter is being used incorrectly just as in your regex example. Whenever a language uses delimiters, you have to treat those characters differently. Even in regex, you have to escape the characters for them to work.

So although I think it's good to have quality documentation, I think that items like this that are present throughout the entire language don't need to be added to the documentation for every command and identifier. Instead, maybe some of the most common mistakes could have their own section for beginners.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2005
Posts: 28
T
Tuxman Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Dec 2005
Posts: 28
Originally Posted By: Riamus2
maybe some of the most common mistakes could have their own section for beginners.

I'd second this. Who is responsible for it?


Gamers.IRC team - gamersirc.net
#Gamers.IRC on QuakeNet (sometimes we're there).
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Khaled does everything with mIRC.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
What is "it" that should be properly documented?

Regular expressions are not a syntax of mIRC, they are a syntax of the PCRE library that mIRC uses. The only thing mIRC does not currently document is that mIRC uses PCRE, though this would likely not change the fact that commas are used in expressions.

Since regexes are not syntax, the expressions themselves are nothing more than string input, like everything else in the language. Regex string input has the same caveats as any other kind of string input when used in $identifiers, where arguments delimit across ",". Using /\d{3,4}/ in an identifier is no different than using:

Code:
//echo -a $len(Hello, how are you?)


If you understand why the above fails, you should understand why regexes fail.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard