How to replace multiple consecutive question marks (?) with a single question mark in Python

1 Answer

0 votes
import re

text = "Hello??? How are you?? What is your Wi-Fi password????";

# Replace multiple consecutive question marks with a single one
result = re.sub(r'\?+', '?', text)

print(result)  



'''
run:

Hello? How are you? What is your Wi-Fi password?

'''

 



answered Jul 24, 2025 by avibootz
...