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.
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Mon Jun 30, 2003 6:22 pm
Greetings,
I read the manuel of Regexp but I still don't get it,
I think its not in manual.
My problem:
This regexp
if {![regexp "^(\[0-9\].\[0-9\])" [lindex $arg 1]]} {
Input like 1.0 works -> CORRECT
Input like x1.0 doesnt work -> CORRECT
But
Input like 1.0xxx <- any other word after that 0 works also
but I want only the user be able to input 1.0 and not 1.0xxx
I tried to add the ^ to the end of the regexp "" but it doenst work that way - which would be easy ;(.
Anyone knows a solution?
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Mon Jun 30, 2003 8:10 pm
add a \$ to the end of your rule
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Tue Jul 01, 2003 4:48 am
Quick tip: Enclose your RegExp expression in curly braces rather than quotes.
This will save the requirment to excape characters, except where you need to force a escape code.
This will make the expression look neater, and save you from having 3 slashes to escape one character.
You above code would become (including fix).
Code: Select all
if {![regexp {^([0-9].[0-9])$} [lindex $arg 1]]} {
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Tue Jul 01, 2003 9:23 am
big thx ppslim worked fine!!
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Tue Jul 01, 2003 9:48 am
if you want to shorten the line you can do this:
Code: Select all
if {![regexp {^(\d.\d)$} [lindex $arg 1]]} {
Elen sila lúmenn' omentielvo
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Tue Jul 01, 2003 10:49 am
...and escaping the "." would make it only match "digit-period-digit" which i suspect is what you want. (the current rule will match "digit-anything-digit")
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Tue Jul 01, 2003 11:15 am
i am using
if {![regexp {^([0-9].[0-9])$} [lindex $arg 1]]} {
right now.
how do i esacpe the "." ?
i want to enforce: digitDOTdigit
digit = 0-9
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Tue Jul 01, 2003 1:11 pm
\.
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Tue Jul 01, 2003 2:23 pm
oops
forgot the dot...
Code: Select all
if {![regexp {^(\d\.\d)$} [lindex $arg 1]]} {
should do the trick
Last edited by
Papillon on Wed Jul 02, 2003 4:17 am, edited 1 time in total.
Elen sila lúmenn' omentielvo
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Tue Jul 01, 2003 2:42 pm
big thanks hehe.
great forum