w3resource logo


Python Exercises

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

Python Regular Expression: Exercise-32 with Solution

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

Sample Solution :-

Python Code :

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

Python Code Editor:

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

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program