Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: python lockfile 
Python :: python add columns to dataframe without changing the original 
Python :: transpose matrice numpy 
Python :: numpy roll 
Python :: How to Replace substrings in python 
Python :: configuring tailwindcss, vue and laravel 
Python :: copy array along axis numpy 
Python :: numpy maximum 
Python :: pandas switch column levels 
Python :: select statement python 
Python :: Generate bar plot python 
Python :: for loop only for first 10 python 
Python :: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. 
Python :: python first 
Python :: crypto trading bot python 
Python :: how to write a function in python 
Python :: adding numbers in python 
Python :: How To Display An Image On A Tkinter Button 
Python :: sample hierarchical clustering 
Python :: how to find duplicate strings in a list of string python function 
Python :: program to replace lower-case characters with upper-case and vice versa in python 
Python :: list count python 
Python :: double for loop in list comprehension 
Python :: generate python 
Python :: prime numbers upto n in python 
Python :: continue statement in python 
Python :: api testing python 
Python :: how to check if digit in int python 
Python :: flask app run 
Python :: Python List count() example with numbers 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =