Reputation: 717
I'm new to regex in Java and am having trouble getting it to work properly. The following code is saying there were no matches found.
pattern = Pattern.compile("EN\\( [ -][0-5]\\)= \\d+.?\\d*E[+-]\\d{2}");
match = pattern.matcher("EN( 0)= 0.000000E+00");
String result = match.group();
As far as I can tell, this should be working. I've been using the Oracle java tutorial on regular expressions to guide me. Any and all help is appreciated.
Upvotes: 1
Views: 62
Reputation: 124215
-
in [ -]
is special character so you must use [ \\-]
Pattern pattern = Pattern.compile("EN\\( [ \\-][0-5]\\)= \\d+.?\\d*E[+\\-]\\d{2}");
Matcher match = pattern.matcher("EN( 0)= 0.000000E+00");
if (match.find())
System.out.println(match.group());
Upvotes: 1
Reputation: 23903
Almost there, you just need:
Matcher match = pattern.matcher("EN( 0)= 0.000000E+00");
match.find(); // <-- missing
String result = match.group();
Upvotes: 2