|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
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)
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
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 :<
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
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.
|
|
|
|
Joined: Dec 2002
Posts: 77
Babel fish
|
Babel fish
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])$/
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
it doesn't work for some numbers like: 106,107 etc
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
that's returns 1 for any number
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Dec 2002
Posts: 77
Babel fish
|
Babel fish
Joined: Dec 2002
Posts: 77 |
duh, yeah, ...it was late...
/^([1-9]\d?|1(?:[01]\d|2[0-5]))$/
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
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..
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
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. - 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!
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
You might find these aliases useful: [color:green]; Usage: $regexless(N)
; Returns the regular expression pattern that matches
; any number smaller than N.
; Examples: $regex(23,$+(/^,$regexless(24),$,/)) -> returns "1"
; but $regex(25,$+(/^,$regexless(24),$,/)) -> 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 (?(?=(?<=^|\D) $+ $regexless($int($1)) $+ (?=\D|$))\x00|\d+)
alias regexless1 {
if ? iswm $1 { return $iif($calc($1 - 1) > 0,$+([0-,$ifmatch,]),0) }
return $iif($calc($left($1,1) - 1) > 0,$+([0-,$ifmatch,]?\d{0,$chr(44),$mid($1,2,0),$chr(125)),0?) $+ $&
$iif($mid($1,2) > 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: 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
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
|
|
|
|
|