You can use
([^:
]*):s*B
See the regex demo. Details:
- a word boundary
([^:
]*)
- Group 1: any zero or more chars other than :
and line feed
:
- a colon
s*
- zero or more whitespaces
B
- a B
char.
See the Python demo:
import re
# Make sure you use
# with open(fpath, 'r') as f: text = f.read()
# for this to work if you read the data from a file
text = """John SMith: A
Pedro Smith: B
Jonathan B: A
John B: B
Luis Diaz: A
Scarlet Diaz: B"""
print( re.findall(r'([^:
]*):s*B', text) )
# => ['Pedro Smith', 'John B', 'Scarlet Diaz']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…