How to find 6 digits in a string in python?
Question: An example string is `"CPLR_DUK10_772989_2"`. I want to pick out `"772989"`
specifically. I would imagine using `re.findall` is a good way to go about it,
however, I don't have a very good grasp on regular expression so I find myself
stumped on this one.

Here is a sample of code that I thought would work, until I looked at the full
list of strings, and saw that it definitely doesn't. I suppose I'm looking for
some more robustness!

    
    
    for ad in Ads:
        num = ''.join(re.findall(numbers,ad)[1:7])
        ID.append(num)
    ID = pd.Series(ID)
    

Other sample strings: `"Teb1_110765"`, `"PAN1_111572_5"`.


Answer: The regex you are looking for is

    
    
    p = re.findall(r'_(\d{6})', ad)
    

This will match a six-digit number preceded by an underscore, and give you a
list of all matches (_should there be more than one_)

**Demo:**

    
    
    >>> import re
    >>> stringy =  'CPLR_DUK10_772989_2'
    >>> re.findall(r'_(\d{6})', stringy)
    ['772989']
    

