Suppose I have a df:
df = pd.DataFrame({'col': ['ABCXDEF', 'ABCYDEF']})
How can I extract the string that is surrounded by ABC & the first occurrence of DEF? Desired output:
col
0 X
1 Y
Note that I don't want a solution based on exact positions, like:
df.col.str[3:4]
df.col.str.extract(r"((?<=ABC).+(?=DEF))")DEF. For example, if the string isABCXDEFDEFDEF.