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 trouble with regex 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 "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
Similar Threads
Could anyone please help me in understanding this pattern
What is wrong with the regex?
missing return statement?
Why doesn't this match?