[英]String in specific format
如果字符串格式正确,我如何检查python?
我有变量标签,它应该是0.0格式
例如
tag = "1.0"
if tag != (is not in format **0.0**):
print("not in tag")"
else:
print("correct tag")"
在 bash 中它看起来像这样
tag="10.0"
if [[ $tag != "${tag%.*}.${tag#*.}" ]]; then
echo "wrong tag"
fi
最简单的实现是使用正则表达式:
if not re.search("^\d+\.\d+$", tag):
#does not match
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.