This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
arfer
Master
Posts: 436 Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK
Post
by arfer » Tue Jan 18, 2005 11:35 am
Attempting regexp for the first time but I can't seem to get the syntax correct.
I want to test if a string is between 1000 and 99999 (I know there are simpler methods than regexp to do this by the way)
# testing script
# format !test <argument>
bind pub - !test ptest
proc ptest {nick uhost hand chan arg} {
if {[regexp \[1-9\]\[0-9\]{3,4} $arg]} {
putserv "PRIVMSG $chan :Regular expression matched"
} else {
putserv "PRIVMSG $chan :Regular expression not matched"
}
}
!test 1024 yields 'Regular expression matched' <--- correct
!test hello yields 'Regular expression not matched' <--- correct
!test 675 yields 'Regular expression not matched' <--- correct
!test 657349 yields 'Regular expression matched' <--- UNEXPECTED
Where am I going wrong please
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Tue Jan 18, 2005 12:39 pm
Have you ever read "The Manual"?
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Tue Jan 18, 2005 12:59 pm
Code: Select all
proc isNumber {num} {
if {[regexp {^[0-9]{4,5}$} $num]} {
return 1
}
return 0
}
this should take care of it cause of the {} it sets a minimum length and numbers with minimum lenght of 4 start from 1000 maximumlength of 5 is 99999 exactly the range you require so..
XplaiN but think of me as stupid
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Tue Jan 18, 2005 1:38 pm
He said 1000-99999, not 0000(aka 0)-99999, and he's already using the sequence quantifier ({})
Have you ever read "The Manual"?
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Tue Jan 18, 2005 6:52 pm
ic indeed 0 is included by length.. well this should work
Code: Select all
proc isNumber {num} {
return [regexp {^[1-9]{1}[0-9]{3,4}$} $num]
}
hmm indeed just as you told hehe
XplaiN but think of me as stupid