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.

Regexp Help!

Old posts that have not been replied to for several years.
Locked
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Regexp Help!

Post by BiLL »

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

Post by user »

add a \$ to the end of your rule :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

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]]} {
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

big thx ppslim worked fine!!
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

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

Post by user »

...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")
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

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

Post by user »

\.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

oops :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
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

big thanks hehe.
great forum :)
Locked