WPF Learner
WPF Learner

Reputation: 161

Regular expression for 5 numbers and 1 Alphabet

Need help to define a regex pattern for 5 numbers and 1 Alphabet. I have defined something like this:

"(?<Code>\d{5}){1}(?<Id>[a-zA-Z]{1}){1}$"

The above pattern also matches "1234567A". How to restrict the numeric to 5 digits in the above pattern?

Upvotes: 1

Views: 265

Answers (1)

Toto
Toto

Reputation: 91498

Use anchors at the begining and the end:

^\d{5}[a-zA-Z]$

or if the string is inside another string:

\b\d{5}[a-zA-Z]\b

Upvotes: 2

Related Questions