I have an expression that could be 13.33
, 15.66-17.22
, 17.33-17.66
. I want to be able to figure out if it has a "-"
(en-dash) in it because that will change how my code runs. I followed this thread to check for matches in an expression.
My regex to find the en-dash is "-"
. My regex expression works online as can be seen here, but fails when used in Java. My code is as follows.
Pattern p = Pattern.compile("-");
Matcher m = p.matcher(refVal);
System.out.println(m.find());
if (m.find()){
//Do stuff
}
With the entry, 17.33–17.66 ref
, the code prints false
.
The expected use cases:
Input: 17.33-17.66 reasdfkljasdfjlkadsf
Output: m.find() should be true
Input: 17.33
Output: m.find() should be false
Input: 2-3 five blah foo
Output: m.find() should be true