Commit 1485e23a by 杨林龙

优化车架号校验

1 parent a461f67c
...@@ -2,7 +2,8 @@ import re ...@@ -2,7 +2,8 @@ import re
def extract_vin(string): def extract_vin(string):
pattern = r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z]{17})" # pattern = r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z]{17})"
pattern = r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z\s\u4e00-\u9fa5]{17})"
match = re.search(pattern, string) match = re.search(pattern, string)
if match: if match:
vin = match.group() vin = match.group()
...@@ -12,6 +13,8 @@ def extract_vin(string): ...@@ -12,6 +13,8 @@ def extract_vin(string):
# 测试字符串 # 测试字符串
test_string = "This is a test VIN: 1HGCM82633A123456 GT800" # test_string = "This is a test VIN: 1HGCM82633A123456 GT800"
test_string = "test 这是一段包含车架号的文本:1HGCM82633A123456"
# test_string = "1HGCM82633A123456"
result = extract_vin(test_string) result = extract_vin(test_string)
print(result) # 输出 1HGCM82633A123456 print(result) # 输出 1HGCM82633A123456
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!