Solved

Positive number match with regular expression in java

Posted on 2010-09-17
4
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

623 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