Possible to Simplify These Python Regular Expressions?
Question: 
        patterns = {}
        patterns[1] = re.compile("[A-Z]\d-[A-Z]\d")
        patterns[2] = re.compile("[A-Z]\d-[A-Z]\d\d")
        patterns[3] = re.compile("[A-Z]\d\d-[A-Z]\d\d")
        patterns[4] = re.compile("[A-Z]\d\d-[A-Z]\d\d\d")
        patterns[5] = re.compile("[A-Z]\d\d\d-[A-Z]\d\d\d")
        patterns[6] = re.compile("[A-Z][A-Z]\d-[A-Z][A-Z]\d")
        patterns[7] = re.compile("[A-Z][A-Z]\d-[A-Z][A-Z]\d\d")
        patterns[8] = re.compile("[A-Z][A-Z]\d\d-[A-Z][A-Z]\d\d")
        patterns[9] = re.compile("[A-Z][A-Z]\d\d-[A-Z][A-Z]\d\d\d")
        patterns[10] = re.compile("[A-Z][A-Z]\d\d\d-[A-Z][A-Z]\d\d\d")
    
        def matchFound(toSearch):
            for items in sorted(patterns.keys(), reverse=True):
                matchObject = patterns[items].search(toSearch)
                if matchObject:
                    return items
            return 0
    

then I use the following code to look for matches:

    
    
            while matchFound(toSearch) > 0:
    

I have 10 different regular expressions but I feel like they could be replaced
by one, well written, more elegant regular expression. Do you guys think it's
possible?

EDIT: FORGOT TWO MORE EXPRESSIONS:

    
    
      patterns[11] = re.compile("[A-Z]\d-[A-Z]\d\d\d")
      patterns[12] = re.compile("[A-Z][A-Z]\d-[A-Z][A-Z]\d\d\d")
    

EDIT2: I ended up with the following. I realize I COULD get extra results but
I don't think they're possible in the data I'm parsing.

    
    
        patterns = {}
        patterns[1] = re.compile("[A-Z]{1,2}\d-[A-Z]{1,2}\d{1,3}")
        patterns[2] = re.compile("[A-Z]{1,2}\d\d-[A-Z]{1,2}\d{2,3}")
        patterns[3] = re.compile("[A-Z]{1,2}\d\d\d-[A-Z]{1,2}\d\d\d")
    


Answer: Sean Bright gave you the answer you need. Here's just a general tip:

Python has wonderful documentation. In this case, you could read it with the
"help" command:

    
    
    import re
    help(re)
    

And if you read through the help, you would see:

    
    
    {m,n}    Matches from m to n repetitions of the preceding RE.
    

It also helps to use Google. "Python regular expressions" found these links
for me:

<http://docs.python.org/library/re.html>

<http://docs.python.org/howto/regex.html>

Both are worth reading.

