2

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+

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Still learning how to use regex I guess.
6

It is not a special character. The dash is there to allow negative numbers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.