Why doesn't this regular expression work in all cases?
===

I have a text file containing entries like this:

@markwarner VIRGINIA - Mark Warner @senatorleahy VERMONT - Patrick Leahy NO @senatorsanders VERMONT - Bernie Sanders @orrinhatch UTAH - Orrin Hatch NO @jimdemint SOUTH CAROLINA - Jim DeMint NO @senmikelee UTAH -- Mike Lee @kaybaileyhutch TEXAS - Kay Hutchison @johncornyn TEXAS - John Cornyn @senalexander TENNESSEE - Lamar Alexander

I have written the following to remove the 'NO' and the dashes using regular expressions:

    import re
    
    politicians = open('testfile.txt')
    text = politicians.read()
    
    # Grab the 'no' votes
    # Should be 11 entries
    regex = re.compile(r'(no\s@[\w+\d+\.]*\s\w+\s?\w+?\s?\W+\s\w+\s?\w+)', re.I)
    no = regex.findall(text)
    
    ## Make the list a string
    newlist = ' '.join(no)
    
    ## Replace the dashes in the string with a space
    deldash = re.compile('\s-*\s')
    a = deldash.sub(' ', newlist)
    
    # Delete 'NO' in the string
    delno = re.compile('NO\s')
    b = delno.sub('', a)
    
    # make the string into a list
    # problem with @jimdemint SOUTH CAROLINA Jim DeMint
    regex2 = re.compile(r'(@[\w\d\.]*\s[\w\d\.]*\s?[\w\d\.]\s?[\w\d\.]*?\s+?\w+)', re.I)
    lst1 = regex2.findall(b)
    
    for i in lst1:
    	print i

When I run the code, it captures the twitter handle, state and full names other than the surname of Jim DeMint. I have stated that I want to ignore case for the regex.

Any ideas? Why is the expression not capturing this surname?





