Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyRegSub
#python 3.6.9 #PyRegSub #this code is created by Rezaul Hoque on February 25,2022; #contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; import re #sub() replacing character s = '######################\n' pick = '#' banner = re.sub(pick,'^',s) print(banner) #sub() with backreference example b = 'Today is a "holiday"' patt= r'\"(.*?)\"' repl = r'[\1]' newstr = re.sub(patt, repl, b) print(newstr) #Sub() example where replacement is a function def dolTak(match): dol = int(match.group()) return str(f'Tk{dol*83}') a = ['2','5','10'] pat = r'\d+' strl = [re.sub(pat, dolTak, i) for i in a] print(strl) #using sub() to change date format date = '02-25-2022' find = '\D' re = re.sub(find,'/',date) print(re) print(banner)
run
|
edit
|
history
|
help
0
Hr
lesson3 part3
binary_search
f strings 3
π―π―π―π―π―π―π―π½Guess the number π½π―π―π―π―π―π―π―
Komalsri123
Faiha - Lesson 8
python, attributes, setter and getter the pythonic way (V2)
Faiha Lesson 2
Prueba