w3resource logo
Python Exercises

Python: Replace all occurrences of space, comma, or dot with a colon

Python Regular Expression: Exercise-31 with Solution

Write a Python program to replace all occurrences of space, comma, or dot with a colon.

Sample Solution:-

Python Code:

import re
text = 'Python Exercises, PHP exercises.'
print(re.sub("[ ,.]", ":", text))

Sample Output:

Python:Exercises::PHP:exercises:  

Python Code Editor:

import re
text = 'Python Exercises, PHP exercises.'
print(re.sub("[ ,.]", ":", text))

Improve this sample solution and post your code through Disqus