Finding letter bigrams in text using Python regex
Question: I am trying to use `re.findall` to find all the sets of two letters following
each other in a text (letter bigrams). How do I get the regex not to consume
the last letter of the previously found bigram, so that it can be used again
in the following?

The following doesn't work, as the regex consumes:

    
    
    >>> re.findall(r'[a-zA-z]{2}', 'find bigrams here')
    ['fi', 'nd', 'bi', 'gr', 'am', 'he', 're']
    

Using a positive lookahead was a second attempt. It doesn't consume the second
letter of the previous bigram, but doesn't catch it either...

    
    
    >>> re.findall(r'([a-zA-z](?=[a-zA-Z]))', 'find bigrams here')
    ['f', 'i', 'n', 'b', 'i', 'g', 'r', 'a', 'm', 'h', 'e', 'r']
    

Thanks for any help.


Answer: 
    import re
    print re.findall(r'(?=([a-zA-Z]{2}))', 'find bigrams here')
    

Output:`['fi', 'in', 'nd', 'bi', 'ig', 'gr', 'ra', 'am', 'ms', 'he', 'er',
're']`

Guess you need this

