Recently I ran into a validation situation I've been trying to solve with regex. The rules are as such:
- Must start with a capital letter
- Center of the string may be of any length
- Center of the string may have any combination of upper and lower case letters and numbers
- Center of the string may have up to one underscore
- Must end with a number
I have attempted to match this string with the following regex:
^(?!_{2,})([A-Z][a-zA-Z0-9_]*[0-9])$
and
^(?<=_{0,1})([A-Z][a-zA-Z0-9_]*[0-9])$
Both of these attempts still match cases where there is more than one underscore present. I.E. App_l_e9 or App__le9.
How can you check to see if your regex match, I.E. the ([A-Z][a-zA-Z0-9_]*[0-9]) part contains zero or one underscore in any place within the middle of the string?