zbparse/flask_app/test_case/test_正则表达式2.py
2024-12-24 10:21:27 +08:00

21 lines
558 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
# 修改后的正则表达式
pattern = re.compile(r'^\d+\s*[.]\s*\d+\s*[.]\s*\d+(?![.])')
# 测试字符串
test_strings = [
'5.1.3 投标文件未按时上传系统的。',
'5.1.3.1 投标文件未按时上传系统的。',
'5.1 投标文件未按时上传系统的。',
'5.1.3 投标成功。',
]
# 测试匹配
for test_string in test_strings:
match = pattern.search(test_string)
if match:
print(f"匹配成功: {match.group()} -> {test_string}")
else:
print(f"未匹配: {test_string}")