mIRC Home    About    Download    Register    News    Help

Print Thread
#27952 03/06/03 08:38 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
$regex($1-,^[0-1]?[0-2]?[1-5]$)
i want it to return 1 only if it's a number between 1 to 125 (i know that this expression is wrong but i'm really don't know other way to do that)


#27953 03/06/03 08:58 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A regular expression really isn't necessary, in fact it would be considerably larger (and presumably slower) than just using $iif($1 isnum 1-125,1,0).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#27954 04/06/03 04:18 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
hmm i didn't asked what is slower and what is not i just want to know how to do that through regular expressions :<

#27955 04/06/03 06:27 AM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Yes but have you considered that we don't want to sit for an hour creating a regex for something that isn't even for us and has another, better method, for doing it? If you really want it done with regex, I really see no reason why we need to do it for you. I'm certainly not going to spend hours doing it when there is already isnum. Just thinking about it in my head, I can see that a regex to do that is going to wind up being rather complex.

#27956 04/06/03 08:28 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
i showed u there regex i did and it's not working, if it takes u a hours to do it u don't have to
my question was for some1 that know good regex and can give me an example for such regular expression cuz i don't have idea how to do that. i hope some1 like qwerty or any1 will help me.
btw i want to do that with regex cuz it's not just the number, there is a big expression and i need to add that thing to there..


Last edited by ScatMan; 04/06/03 08:30 AM.
#27957 04/06/03 09:45 AM
Joined: Dec 2002
Posts: 77
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2002
Posts: 77
Don't know if there is a shorter way, but here goes...

/^([1-9]\d?|1[0-2][0-5])$/

#27958 04/06/03 09:54 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
it doesn't work for some numbers smirk like:
106,107 etc

#27959 04/06/03 11:02 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
OK, here:
(0?0?[1-9]|0?[1-9]\d|1[01]\d|12[0-5])
There's probably a smaller/quicker/better way to do it with regex, but this is the easiest expression to come up with. I didn't test it a whole lot so I can't say for certain it's bulletproof.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#27960 04/06/03 11:32 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
that's returns 1 for any number

#27961 04/06/03 11:46 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Well it requires a ^ at the start and a $ at the end if you're using it alone. But I thought the entire point of you wanting to use a large/slow regular expression was because you wanted to insert it into a larger expression - obviously you can't do that with ^ and $ on it so I removed them.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#27962 04/06/03 11:53 AM
Joined: Dec 2002
Posts: 77
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2002
Posts: 77
duh, yeah, ...it was late...

/^([1-9]\d?|1(?:[01]\d|2[0-5]))$/

#27963 04/06/03 11:56 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
well, i'm trying to check now if it's the number in the whole expression that's why i add the ^ and $ but it should work..

#27964 04/06/03 11:58 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
oh
thanks

#27965 05/06/03 03:12 AM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
/^(?:[1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-5])$/

A nice simple straight forward attack. grin

- Raccoon

Actually, this is pretty much Starbuck's method, except I didn't include padded 0's, and [01] is just as good/better than [0-1]. Note however (?:expression) is much faster than (expression) if you're just grouping and not back-referencing.

Last edited by Raccoon; 05/06/03 03:21 AM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#27966 05/06/03 03:45 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You might find these aliases useful:
Code:
[color:green]; Usage: $regexless(N)
; Returns the regular expression pattern that matches 
; any number smaller than N.
; Examples: $regex(23,$+(/^,$regexless(24),$,/)) -&gt; returns "1"
; but $regex(25,$+(/^,$regexless(24),$,/)) -&gt; returns "0"[/color]
alias regexless {
  var %a 
  !.echo -q $regsub((?: $+ $regexless1($int($1)) $+ ),/\(\?:(\[0-\d\]|\d)\)/g,\1,%a) 
  return (?=\d)0* $+ $replace(%a,$+({0,$chr(44),1}),?)
}

[color:green]; Usage: $regexgreater(N)
; Returns the regular expression pattern that matches 
; any number bigger than or equal to N.[/color]
alias regexgreater return (?(?=(?&lt;=^|\D) $+ $regexless($int($1)) $+ (?=\D|$))\x00|\d+)
alias regexless1 {
  if ? iswm $1 { return $iif($calc($1 - 1) &gt; 0,$+([0-,$ifmatch,]),0) }
  return $iif($calc($left($1,1) - 1) &gt; 0,$+([0-,$ifmatch,]?\d{0,$chr(44),$mid($1,2,0),$chr(125)),0?) $+ $&amp;
    $iif($mid($1,2) &gt; 0,| $+ $left($1,1) $+ (?: $+ $regexless2($ifmatch) $+ ))
}
alias regexless2 return $regexless1($1)


The regexless1 and regexless2 aliases are auxiliary, they are not meant to be called by the user.

Here's an example of using $regexless() to make an IP validator:
Code:
alias isip { 
  var %a = $regexless(256), %r = /^(?: $+ %a $+ \.){3} $+ %a $+ $!/
  if $regex($1,%r) { return $true }
  return $false
}
$isip(N) returns $true if N is a valid IP number, otherwise $false


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#27967 05/06/03 07:06 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
oh ty


Link Copied to Clipboard