Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
 
PREVIOUS NEXT
Tagged: #python #remove #occurrence #character #string
ADD COMMENT
Topic
Name
7+3 =