This is one of those "I'd know how to do it in C" type questions. :p I'm asking this as similar questions in SO don't have a particular aspect I'm looking for.
I'm essentially looking to find and replace items that also have possessive forms. So if there is a "rabbit" in the list, and also a "rabbit's", then replace "rabbit" with a series of asterisks.
Something along the lines of:
#!/usr/bin/env python
import re
text = open("list.txt", "w")
for line in text:
test = line
if re.match(test+"'", line) or re.match(test+"'s", line):
line = "****"
However, this clearly won't work as the for each mechanism makes line be used for both iteration and pattern matching.
test = lineand thenre.match(test+"'", line), how is that supposed to work?line = "****"does nothing in this case, variable is recreated in the loop for each element.