我有一堆字符串,但我只想保留这种格式的字符串:
x/x/xxxxxx:xx
检查字符串是否符合这种格式的最简单方法是什么? (假设我想检查它是否有 2 个/'s 和一个 ':' )
最佳答案
尝试使用正则表达式:
import re
r = re.compile('.*/.*/.*:.*')
if r.match('x/x/xxxx xx:xx') is not None:
print 'matches'
你可以调整表达式来满足你的需要
关于python - 检查 python 字符串格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14966647/