| Author |
Regular Expression
|
faisal hameed
Ranch Hand
Joined: Jan 19, 2009
Posts: 48
|
|
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
|
Regards, M Faisal Hameed
PUCIT, Pakistan
|
 |
Kiaamaa Liammes
Ranch Hand
Joined: Oct 03, 2009
Posts: 32
|
|
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
|
SCJP ,SCWCD
|
 |
faisal hameed
Ranch Hand
Joined: Jan 19, 2009
Posts: 48
|
|
Thanks for your response.
But how i can modify it so that it can accept only one dot(.) anywhere.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
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
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
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
Joined: Oct 03, 2009
Posts: 32
|
|
|
faisal plzz refer this link and try for the regex you want RegEx Tutorial
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
|
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.
|
Mohamed Sanaulla | My Blog
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
|
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.
|
 |
 |
|
|
subject: Regular Expression
|
|
|