Positive number match with regular expression in java

Posted on 2010-09-17
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?

Question by:theartha
  • 3
LVL 86

Accepted Solution

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

Open in new window


Author Comment

ID: 33703260

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

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
LVL 86

Expert Comment

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

Open in new window

LVL 86

Expert Comment

ID: 33703396

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simple java question 3 55
Finding (and replacing) text between two strings in Php 7 57
diffSum example 4 36
expectj telnet failing 5 36
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

770 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