This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes trouble with regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble with regex" Watch "trouble with regex" New topic

trouble with regex

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i'm trying to validate this string representing money, and i want it to be like

so i'm using this method:
public static boolean valida(String valor)

throws NumberFormatException {

if ( valor.matches ( "[0-9] + (\\.[0-9]{1,2})" ) ) {

return true;


else return false;


but when i test, i allways get an assertion failed:

What am i doing wrong?


java amateur
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i found it out:
should be:

[ August 23, 2005: Message edited by: miguel lisboa ]
I agree. Here's the link:
subject: trouble with regex
It's not a secret anymore!