All Posts Create a Post  
0
votes
465
views
Regular expression to replace second occurrence of dot
Posted at 6 months, 2 weeks ago / May 19, 2021, noon

String is Hello.world.hello. I wanted to replace the second occurrence of the dot with ‘_’. str = "Hello. world. Hello!" x = re.sub(r'^((.){1}).', r'\1_', str) #x = str.find(str.find('.') print(x) The …

146 3 3 0