File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression for "1.0"

 
shukla raghav
Ranch Hand
Posts: 203
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47278
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be careful about spellings: it's not "wud" but "would".
 
Praveen Rajendran
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47278
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted
 
shukla raghav
Ranch Hand
Posts: 203
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic