1syntax
2re.sub(pattern, repl, string, max=0)
3#!/usr/bin/python
4import re
5
6phone = "2004-959-559 # This is Phone Number"
7
8# Delete Python-style comments
9num = re.sub(r'#.*$', "", phone)
10print "Phone Num : ", num
11#output Phone Num : 2004-959-559
12
13# Remove anything other than digits
14num = re.sub(r'\D', "", phone)
15print "Phone Num : ", num
16#output Phone Num : 2004959559
1# credit to the Stack Overflow user in the source link
2
3re.sub('(\s+)(a|an|and|the)(\s+)', '\1\3', text) # leaves the residual whitespace
4
5re.sub('\s+(a|an|and|the)(\s+)', '\2', text) # removes the whitespace