Return reoccuring regex matches with python
Question: I have a string:

    
    
    SomeTextSomeTextA _SomeThing_ BSomeTextSomeTextA _SomeThingElse_ BSomeText

I want to have the Strings SomeThing and SomeThingElse string returned because
they are bracketed with A and B and assuming SomeText does not contain any A
... B occurences.

Any hint would be highly appreciated.

Here's what I tried, but it doesn't work:

    
    
    import re
    
    string = 'SomeTextSomeTextASomeThingBSomeTextSomeTextASomeThingElseBSomeText'
    regex='(A.*B)'
    

I guess neither the regex is correct, nor do I know how to access the matches.
Is it match of `finditer` or…?


Answer: Try using `re.findall`:

    
    
    >>> print re.findall('A(.*?)B', s)
    ['SomeThing', 'SomeThingElse']
    

See it working online: [ideone](http://ideone.com/20QrS)

Note the question mark. Without it the matching is done greedily - it will
consume as many characters as possible.

