This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression

 
faisal hameed
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to match the decimal values by using regex matcher of java.How can i do that?

Examples.

3
3.3
34.009
0.34

but not
.3
 
Kiaamaa Liammes
Ranch Hand
Posts: 32
Eclipse IDE Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure whether I followed the requirement correctly or not, this code will not match any expression which does not have anything before this decimal

 
faisal hameed
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response.
But how i can modify it so that it can accept only one dot(.) anywhere.
 
Henry Wong
author
Marshal
Pie
Posts: 21208
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Just "eyeballing" this, but won't this also match something like.... "1 flew over the cuckoo's nest"? I don't think this is what the OP wants.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 21208
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
faisal hameed wrote:Thanks for your response.
But how i can modify it so that it can accept only one dot(.) anywhere.


This is generally what happens with regular expressions -- when you try to get help from the net, but don't understand the code that you got. You wind up not being able to modify it, or even understand if it works or not.

You really need to start with a tutorial on regex, in order to understand it. Otherwise, you wind up using code that you don't understand, and that is *never* a good thing.

Anyway...



Henry
 
Kiaamaa Liammes
Ranch Hand
Posts: 32
Eclipse IDE Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
faisal plzz refer this link and try for the regex you want RegEx Tutorial
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel that Regular expressions are something which are very useful to learn. I remember listening to one of the speakers at a local JUG meet about this book- Mastering Regular Expressions. Supposed to be really useful book.
 
Stephan van Hulst
Bartender
Pie
Posts: 5898
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are indeed very useful. But at the same time, I think people resort to them too quickly to solve problems that can be solved more elegantly using 'conventional' code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic