Python 正则表达式搜索和替换 Python 正则表达式 匹配(match) vs 搜索(search) Python CGI 程序 Python 正则表达式搜索和替换 #!/usr/bin/python import re phone = "2004-959-559 # This is Phone Number" # Delete Python-style comments num = re.sub(r'#.*$', "", phone) print "Phone Num : ", num # Remove anything other than digits num = re.sub(r'\D', "", phone) print "Phone Num : ", num Python 正则表达式 匹配(match) vs 搜索(search) Python CGI 程序