strip multiple characters python code example
Example 1: strip characters from string python regex
syntax
re.sub(pattern, repl, string, max=0)
import re
phone = "2004-959-559 # This is Phone Number"
num = re.sub(r'#.*$', "", phone)
print "Phone Num : ", num
num = re.sub(r'\D', "", phone)
print "Phone Num : ", num
Example 2: python strip characters
string = " python strip method test "
print(string)
print(string.strip())
print(string.strip(' strip'))
Output:
python strip method test
python strip method test
python method test
Example 3: python remove multiple characters from string
import re
print(re.sub("e|l", "", "Hello people"))
"Ho pop"