Answers for "python remove second occurrence of character in string"

0

python remove second occurrence of character in string

import re 
#Remove the second Hello from example

example = "Hello, world. Hello!" 
print re.sub(r'^((.*?Hello.*?){1})Hello', r'\1Goodbye', str) 
# Prints "Hello, world. Goodbye!"

#To remove any particular occurance adjust the {1} to the desired number
Posted by: Guest on October-13-2021

Code answers related to "python remove second occurrence of character in string"

Python Answers by Framework

Browse Popular Code Answers by Language