I am trying to figure out how to remove the last occurrence of a string of characters at the bottom of a file. I've got the following script, but it's not doing as requested. Any ideas would be greatly appreciated.
iter = r"(\*)+"found = re.findall(iter, finalOutput)[-1]finalOutput.replace(found, "")
I also allowed for space characters after the last * characters, just in case there are some.
gelonida
Could you please clarify:
You have a huge string spanning multiple lines.
You want to find the last occurence of one or more stars and replace them with nothing?
Do these stars have to be in a separate line?
could there be whitespace before or after these stars?
could there still be some text / code after these stars??
Open in new window
I also allowed for space characters after the last * characters, just in case there are some.