I am trying to remove all punctuation marks from a string except (.) and (:). This is what I have implemented:
import string
import re 
remove = string.punctuation
remove = remove.replace(".", "")
pattern = r"[{}]".format(remove) 
line = "NETWORK  [listener] connection accepted from 127.0.0.1:59926 #4785 (3 connections now open)"
re.sub(pattern, "", line) 
Current output:
NETWORK  listener connection accepted from 12700159926 4785 3 connections now open
Desired output:
NETWORK  listener connection accepted from 127.0.0.1:59926 4785 3 connections now open
What am I doing wrong? Thanks for the help!
 
     
     
    