mIRC Homepage
Posted By: SGR $regex problem - 03/07/06 01:22 AM
Code:
alias checksteam {
  if ($regex($1-,/^STEAM_[01]:[01]:\d{2,10}$/) > 0) {
    return $true
  }
  return $false
}


Any reason why this always returns $false? Even if a string matching the Regex is provided as the argument? Indeed, how can I get this to perform "as expected" for the regex:
Code:
/^STEAM_[01]:[01]:\d{3,11}$/

I've tried using "$+ $chr(x) $+" in place of [, : and ] -- didn't get me anywhere.

Thanks in advance,

Alex.
Posted By: RusselB Re: $regex problem - 03/07/06 01:33 AM
I don't know much about regex, but I did note that your code will always return $false, even if it also returns $true

The correct format (to keep both from happening) would be
Code:
alias checksteam {
  if ($regex($1-,/^STEAM_[01]:[01]:\d{2,10}$/) > 0) {
    return $true
  }
  else {
    return $false
  }
} 


I don't know if that solves the problem (ie: there were times when you were getting both $true and $false returned) or if there is a problem with the regex, which always caused just the $false to be returned.
Posted By: SGR Re: $regex problem - 03/07/06 01:37 AM
Funnily enough, I did actually have it using the method you described, I removed it from my post as it appeard to be redundant code. Still, I'll keep that behaviour in mind for the future.

Regardless, even using a full if{}else{} block; the same behaviour is still observed ($false is always returned)
Posted By: schaefer31 Re: $regex problem - 03/07/06 01:40 AM
There's a problem with using {2,10} in the same line since it has a comma. You need to put the pattern into a variable and use that instead.

Code:
alias checksteam {
  var %r = /^STEAM_[0-1]:[0-1]:\d{2,10}$/
  return $regex($1-,%r)
}


Returns 1 if valid and 0 if not. There's certainly no need to use an if-else here.

if (1) and if ($true) are essentially the same, as are if (0) and if ($false).

So, using this in another script:

if ($checksteam(id)) will be false if it returns 0 and true if it returns 1.
Posted By: SGR Re: $regex problem - 03/07/06 02:11 AM
Strange, I thourght I'd replied to this already. NEvermind.

Anyway, thanks schaefer31, yes the , was the problem - thanks.

I'm surprised mIRC doesn't stop parsing for paramters when it encounters the / and not start again until the ending / of the regex but heh.

Quirks there will always be.
Posted By: qwerty Re: $regex problem - 03/07/06 11:33 AM
Quote:
[...] your code will always return $false, even if it also returns $true


This is impossible, a routine can never return twice. When the first /return is encountered, execution stops. His usage of /return's is absolutely correct and in fact saves a few characters (and CPU cycles) by avoiding /else.
© mIRC Discussion Forums