basically i want to write a script that will sanitize a URL, will replace the dots with "(dot)" string. For example if i have http://www.google.com after i run the script i would like it to be http://www(dot)google(dot). Well this is pretty easy to achieve with .replace when my text file consist only of urls or other strings, but in my case i also have IP addresses inside my text file, and i dont want the dots in the IP address to change to "(dot)".
I tried to do this using regex, but my output is " http://ww(dot)oogl(dot)om 192.60.10.10 33.44.55.66 "
This is my code
from __future__ import print_function
import sys
import re
nargs = len(sys.argv)
if nargs < 2:
sys.exit('You did not specify a file')
else:
inputFile = sys.argv[1]
fp = open(inputFile)
content = fp.read()
replace = '(dot)'
regex = '[a-z](\.)[a-z]'
print(re.sub(regex, replace, content, re.M| re.I| re.DOTALL))
I guess i need to have a condition which checks that if the pattern is number.number - dont replace.