I am trying to extract certain words between some text and symbol using regex in Python Pandas. The problem is that sometimes there are non-characters after the word I want to extract, and sometimes there is nothing.
Here is the input table.
Here is the expected output.
I've tried this str.extract(r'[a-zA-Z\W]+\s+Reason to buy:([a-zA-Z\s]+)[a-zA-Z\W]+\s+') but does not work.
Any advice is appreciated.
Thanks.
source https://stackoverflow.com/questions/75238599/python-pandas-extract-text-between-words-and-symbols-with-regex
Comments
Post a Comment