I am trying to use to do a regex extract with Pandas by using the value from another column as a variable.
df = pd.DataFrame({'text': ["The final is one of the most famous snooker matches of all time and pa", "Davis trailed for the first time at the event in the quarter-finals, as he played Terry Griffiths. "],'key': ["snooker", 'quarter-finals']})
I was thinking of building a string as a parameter and passing it to the function like so
reg = '((?:\S+\s+){0,10}\b'+'snooker'+'\b\s*(?:\S+\b\s*){0,10})'
df['text'].str.extract(r'reg')
but it generates this error
ValueError: pattern contains no capture groups
which I am assuming is due to the syntax of "(r'reg')"