Solved

Positive number match with regular expression in java

Posted on 2010-09-17
4
674 Views
Last Modified: 2012-05-10
Hi There,

I am trying to match ONLY positive number of type Double with a regular expression in Java.

any clues?

Thanks.
0
Comment
Question by:theartha
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 33703194
Try matching the following:
	final String NO_NEG = "(?<!-)\\d*\\.\\d+";

Open in new window

0
 

Author Comment

by:theartha
ID: 33703260
@CEHJ:

How to compare that NO_NEG string with my input value.?

i.e
Pattern pattern = Pattern.compile(NO_NEG);
Matcher matcher1 = pattern.matcher(amount);  
matcher1.matches()== true{
//do something
}

Error: The method matcher(CharSequence) in the type Pattern is not applicable for the arguments
 (Double)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33703314
Simply
boolean ok = amount.matches(NO_NEG);

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33703396
:-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I remove all except the numbers?  PHP  Regex 3 43
throw exception 21 58
going to wrong jsp page 2 33
Problem to Alipay 10 42
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question