regex to match one and only one digit

Viewed 14937

I need to match a single digit, 1 through 9. For example, 3 should match but 34 should not.

I have tried:

\d
\d{1}
[1-9]
[1-9]{1}
[1-9]?

They all match 3 and 34. I am using regex for this because it is part of a much larger expression in which I am using alternation.

1 Answers
Related