User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 423,365 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,025 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1577 | Replies: 4
Reply
Join Date: Aug 2007
Posts: 3
Reputation: man in a can is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
man in a can man in a can is offline Offline
Newbie Poster

Regular Expressions with Decimal Points

  #1  
Feb 8th, 2008
Hi Folks,
I have been searching to find a reglular expression that deals with decimal points, they are not mentioned on the Sun Tutorials for Regular Expressions. Basically im trying to verify that a string taken in from a screen matches the format of (15).99. This is not for my homework assignment:-) If anyone even knows of a good tutorial that covers this, that would be great as im kinda new to Java development.

Thanks

Man In A Can
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 181
Reputation: stultuske is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
stultuske's Avatar
stultuske stultuske is offline Offline
Junior Poster

Re: Regular Expressions with Decimal Points

  #2  
Feb 8th, 2008
1. check for the number of decimal points in the input. if this is not 1 => false
2. check that everything before the decimal point is a decimal. if not => false
3. check that everything after the decimal point is a decimal if not so=> false
4. check the number of decimals after the decimal pont. if not two => false

if all these checks cleared, you've got a match. don't know whether or not regex has a quick sollution for it, but you could as well do it without
Reply With Quote  
Join Date: Aug 2007
Posts: 3
Reputation: man in a can is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
man in a can man in a can is offline Offline
Newbie Poster

Re: Regular Expressions with Decimal Points

  #3  
Feb 8th, 2008
Cool Thanks very much, i actually worked it out, i had been using "[0-9]{0,15}.{1}[0-9]{2}" and i have since found that this "[0-9]{0,15}[.]{1}[0-9]{2}" will work.

Thanks

Man In A Can
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,816
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 282
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Posting Maven

Re: Regular Expressions with Decimal Points

  #4  
Feb 8th, 2008
You can simplify it just a little more with a digit character match like so
\d{0,15}\.\d{0,2}
You might find this small regex testing form that I posted a while back helpful in tweaking patterns as you are experimenting: http://www.daniweb.com/forums/post392585-8.html
The numbered text fields at the bottom are the match group results of the pattern.
Reply With Quote  
Join Date: Aug 2007
Posts: 3
Reputation: man in a can is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
man in a can man in a can is offline Offline
Newbie Poster

Re: Regular Expressions with Decimal Points

  #5  
Feb 11th, 2008
Thanks very much for all your help.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 12:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC