-2

I know how to check if a String is a positive double but how can I incorporate the function to check if the word is sell also?

This is what I use to check for positive double

sell2.matches("[+]?\\d*\\.?\\d+"))

EDIT: Answer in comment

Fenzox
  • 334
  • 4
  • 20

1 Answers1

-1
private static final Pattern VALIDATOR = Pattern.compile("\\+?\\d+(\\.\\d+)?|all");
...
VALIDATOR.matcher(sell2).matches()

This is the regex you describe. Best have it compiled statically like this, otherwise calling sell2.matches(...) compiles it every time, and that's a performance hit.

coladict
  • 4,799
  • 1
  • 16
  • 27