Reputation: 3953
I would like to write Java regex where plus at the beginning is optional
I try this but not working correctly
[+]+[0-9]{3,}
so that +123 and 123 is valid
What I am doing wrong?
Upvotes: 1
Views: 55
Reputation: 3034
As Hamza commented below, use [+]?[0-9]{3,}
. A question mark means one or none of the previous, which in this case means one or no + before the three numbers.
Upvotes: 2