Reputation: 59
This expression evaluates a string to see if every character is a digit. I don't understand the -?
. I know that ?
means once or no times, but I'm not sure what putting dash in front of it means.
-?\d+
Upvotes: 2
Views: 80
Reputation: 5241
It is not a special character. The dash is there to allow negative numbers.
Upvotes: 6
Reputation: 70929
This is needed because an integer may be negative in which case it will start with a minus (-
). So what you do here is to check for sequence of 1 or more digits optionally preceded by a single minus.
Upvotes: 7