Are you specifically grouping them to pull them out? If not, you can omit the parentheses - have you tried [0-9]+ for the digits?
Is there anything on the line either before or after that is matched? You might need a .* to continue the search through the end of the line...
What are you trying to parse/find?
I need to verify a serial number is correct. Ok this is what I have now:
public static boolean validateValue(String value)
{
Pattern p = Pattern.compile("[0-9]+[-]*[\\s]*");
Matcher m = p.matcher(value);
return m.find();
}
The thing is the string must contain as least 1 digit, but the "-" and " " characters are optional (there can be zero or more of them). No other characters are allowed. The "No other characters allowed" part is the main issue I've been having whenever I think I've solved the problem. Should I do another check of some sort before? I'm not sure how to do the nots for the optional "-" and " " characters when at least 1 digit is required.