I am trying to write a simple regex that finds if the last word in the string is a specific one.
I wrote something like this "(\W|^)dog$". (Check if last word in the sentence is dog)
This regex is correct but in python it is returning nothing when i type something like "I like dog".
I tested this in the Rubular regex editor and it seems to work.
Am I doing something wrong ?
EDIT : Adding my simple code
import re
pm = re.compile("(\W|^)dog$")
has = pm.match("i love dog")
print(has)
df.str.replace(r"(\W|^)(dog|cat)$", ' ')this worked for a list of terms in python pandas