This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regular expression for Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular expression for "1.0"" Watch "Regular expression for "1.0"" New topic
Author

Regular expression for "1.0"

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
i ahve written a small set of statements to identify decimal numerals, i think the code is fine but its not working..



whats wrong with the code ? why is it not working? what will be the correct regex expression of identifying fractional values ?
Praveen Rajendran
Greenhorn

Joined: Dec 25, 2009
Posts: 21
Hi Shukla,

I guess the reason why this wud would have given you false back is because the regex defined by you does not match any character beyond the decimal.

ie it wud would have returned true if your string was "1." and not 1.0"

The below regex wud would work to match 1 or 2 decimal places.


Let me know if it helps.


Thanks & Regards,
Praveen
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Please be careful about spellings: it's not "wud" but "would".
Praveen Rajendran
Greenhorn

Joined: Dec 25, 2009
Posts: 21
Hi Campbell,

Apologies for the short words . Thanks for bringing to attention . Corrected the same with a strike through.

I am new to replying posts in Javaranch. Till date was only reading it. Thought of putting some time to help other to the way I can. Will take care going forward about spellings
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Apologies accepted
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
well praveen, i got the answer for the same long back. In s.matches("\\d(\\.)") the regex expression applies to the entire string, i mean if the string was str = 2. or 654. then this expression would have worked out.But for a string like 2.34 the correct regex would be "\\d\\.\\d+" now it will work.

Anyways thanks for your effort.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular expression for "1.0"
 
Similar Threads
how this expression works. "/\s/g"
question on expressions
Error coming while using c:out tag in JSTL
Calculating Interest Payments
JSTL not working