Python: multiple string test for standard Uk reg, why not working?
Question: The following is a section that has been separated from the main program to
just test the snippet if it works. The "yes" output was for testing each
string method required to see where errors arises. This does not seem to work
and I cant figure out why as I have put all tests for standard UK reg,
checking characters as they appear from an input.

As you can see im a very low level (new to python) programmer, please consider
that as you are providing solutions. Many thanks

    
    
    def main():
        reg_number=input("What is your reg number?: ")
        correct_length = False
        first_two_char_capital = False
        next_two_char_digits= False
        next_char_space = False
        last_three_char_capital= False
    
        first_two_char_capital =reg_number[0:2]
        print(first_two_char_capital)
        next_two_char_digits=reg_number[2:4]
        print (next_two_char_digits)
        next_char_space=reg_number[4:5]
        print(next_char_space)
        last_three_char_capital=reg_number[5:8]
        print (last_three_char_capital)
    
        if len (reg_number) >= 8:
               correct_length = True
               print("yes1")
    
               for ch in reg_number:
                   if first_two_char_capital.isupper():
                       first_two_char_capital = True
                       print("yes2")
                   if next_two_char_digits.isdigit():
                       next_two_char_digits = True
                       print("yes3")
                   if next_char_space.isspace():
                       next_char_space = True
                       print("yes4")
                   if last_three_char_capital.isupper():
                       last_three_char_capital = True
                       print("yes5")
               if correct_length and first_two_char_capital and next_two_char_digits and next_char_space and last_three_char_capital:
                   is_valid = False
                   print(reg_number, "is a non-standard_registration")
               else:
                   is_valid = True
    
                   print(reg_number, "is a standard registration")
                   return is_valid
    
    main()
    


Answer: It's much easier to just use a regular expression here, eg:

    
    
    import re
    
    if re.match('[A-Z]{2}\d{2} [A-Z]{3}$', input('What is your regnumber:')):
        print('yeah it matches...')
    

