Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2008, 12:26 PM
JayEdgar JayEdgar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 14 JayEdgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 35 sec
Reputation Power: 0
Another Regex

My brain is starting to get into it, but not quite.

I want to check for a float number, which would accept all of the following:

1
1.1
.1
0 through 999
remove spaces surrounding
return the entire number

it should not accept:
.
letters, etc...

Here's my expression so far:

^\s*((?:[0-9]{1,3}(?:\.[0-9]*)?)|(?:.[0-9]+))\s*$

Here's what I THINK it does--please correct me (since I'm obviously wrong):

EITHER
3 digits, optional decimal by unlimited digits
OR
decimal, unlimited digits

but it accepts 131313. I don't understand why. It shouldn't accept anything larger than 3 digits (999).

Help is appreciated.

Jay

Reply With Quote
  #2  
Old November 26th, 2008, 12:53 PM
JayEdgar JayEdgar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 14 JayEdgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 35 sec
Reputation Power: 0
I started with an example from RegexBuddy and fashioned it into this:

/^\s*([0-9]{0,3}(?:\.[0-9]*)?)\s*$/

I then checked outside that that the value wasn't null (which should cause nothing to happen).

I guess I'm getting it a bit more...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Another Regex

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap