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.

help with correct regexp syntax needed

Old posts that have not been replied to for several years.
Locked
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

help with correct regexp syntax needed

Post by arfer »

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 avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: help with correct regexp syntax needed

Post by user »

Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

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 avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

why did you post that?

Post by user »

He said 1000-99999, not 0000(aka 0)-99999, and he's already using the sequence quantifier ({})
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

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
Locked