import retext = """John SMith: APedro Smith: BJonathan B: AJohn B: BLuis Diaz: AScarlet Diaz: B"""print( re.findall(r'\b([^:\n]*):\s*B', text) )
Standard input is empty
['Pedro Smith', 'John B', 'Scarlet Diaz']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!