Python only find string with specific length numbers
Question: I am trying to create a script that search for strings of numbers with only
specific length numbers from an output.txt.

Example output.txt:

    
    
    12345678
    77777
    12123887
    

When I use:

    
    
    import re 
    f = open('output.txt', 'r')
    strings = re.findall(r'(\d{5,5})', f.read())
    print strings
    

I would like to get only output: `77777` instead of:

    
    
    12345
    77777
    12123
    


Answer: Use `^(\d{5})$` and `re.MULTILINE`

    
    
    >>> import re
    >>> data = '''12345678
    77777
    12123887'''
    >>> p = re.compile(r'^(\d{5})$', re.MULTILINE)
    >>> re.findall(p, data)
    ['77777']
    >>>
    

