Regular Expression Letter followed by numbers or numbers and a letter

asp.net, c#, regex

Solution

^[G][0-9]{1,5}?$|^[G][0-9]{4}[A-Z]?$

`^[G]` means starts with G `[0-9]{1,5}` means next 1 to 5 letters are numeric `[0-9]{4}` means next 4 letters are numeric `[A-Z]` means last character must be a letter between A -Z.

Problem

I am having some difficulty with the following for a regular expression: G followed by 1-5 numbers or G followed by 4 numbers followed by a single letter A-Z Could someone please assist? e.g. of valid entries would be: ``` G2 G12 G123 G1234 G12345 G1234A ``` Thanks

Original source