How can I use regex to search for repeating word in a string in Python?
Question: Is it possible to search for a repeating word in a string use regex in
**Python**?

For instance:

    
    
    string = ("Hello World hello mister rain")
    
    re.search(r'[\w ]+[\w ]+[\w ]+[\w ]+[\w ]', string)
    

Can I do it so I won't have to repeat `[\w ]+[\w ]`. Can't I just specify `[\w
]*5` instead?


Answer: I think this would be easier using plain Python:

    
    
    from collections import Counter
    
    string = "Hello World hello mister rain" # note: no () needed
    words = string.split()
    
    for word, count in Counter(map(str.lower, words)).iteritems():
        if count > 1:
            print "The word '{}' is repeated {} times.".format(word, count)
    

