troubleshooting Question

Remove last occurrence of characters

Avatar of pingeyeg
pingeyeg asked on
Regular ExpressionsPython
6 Comments2 Solutions1104 ViewsLast Modified:
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, "")

The code I'm running this on is:

*******************************
text
*******************************
<code>

*******************************
text
*******************************
<code>

*******************************
text
*******************************
<code>

*******************************  <-- this line

I want to remove only the last set of *'s.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros