Reputation: 3244
I want my operator
variable matches a list of possible operators ("+", "-", "*", "/", "^") for exactly once, so I did
operator.matches(Pattern.quote("[+-*/^]??"))
It doesn't work. Did I do anything wrong?
Upvotes: 2
Views: 50
Reputation: 8214
Pattern.quote
would quote your whole input. It will not magically ignore your []??
and only look at things inside the []
.
You should use this instead.
operator.matches("[" + Pattern.quote("+-*/^") + "]??")
Upvotes: 4