How to case insensitive remove specific character from string in Python

1 Answer

0 votes
import re

s = "Python c c++ PHP c#"

ch = "p"
empty = ''

s = re.sub('(?i)' + re.escape(ch), lambda m: empty, s)

print(s)


  
'''
run:
    
ython c c++ H c#

'''

 



answered Sep 30, 2022 by avibootz
...