{"id":52751,"date":"2024-12-03T09:29:28","date_gmt":"2024-12-03T01:29:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52751\/"},"modified":"2024-12-03T09:29:28","modified_gmt":"2024-12-03T01:29:28","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e9%aa%8c%e8%af%81%e9%95%bf%e5%ba%a6%e4%b8%ba6%e8%87%b37%e4%bd%8d%e7%9a%84%e6%95%b0%e5%ad%97%e6%88%96%e6%98%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52751\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f <\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f \u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323267136741353928a16.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5339\u914d\u7279\u5b9a\u683c\u5f0f\u7684\u6570\u5b57\u5e8f\u5217<\/strong><\/p>\n<p>\u8981\u6c42\u5339\u914d\u4e00\u7ec4\u7531\u7a7a\u683c\u5206\u9694\u5f00\u7684\u6570\u5b57\u5e8f\u5217\uff0c\u9650\u5b9a\u6761\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u957f\u5ea6\u4e3a 6 \u81f3 7 \u4f4d<\/li>\n<li>\u53ea\u80fd\u5305\u542b\u6570\u5b57\u6216\u661f\u53f7\uff08*\uff09<\/li>\n<\/ul>\n<p><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Python \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5757\u8fdb\u884c\u5339\u914d\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u9a8c\u8bc1\u4e0a\u8ff0\u683c\u5f0f\uff1a<\/p>\n<pre>import re\n\ndef check_format(input_string):\n    # \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d 6 \u6216 7 \u4e2a\u7531\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\u6216\u661f\u53f7\n    pattern = r'^(\\d|\\*)+(\\s(\\d|\\*)+){5,6}$'\n    match = re.fullmatch(pattern, input_string)\n    return match is not None<\/pre>\n<p>\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u9010\u4e00\u5206\u89e3\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>^(\\d|\\*)+: \u5e8f\u5217\u7684\u5f00\u5934\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u6216\u661f\u53f7\u3002<\/li>\n<li>(\\s(\\d|\\*)+){5,6}: \u5e8f\u5217\u5305\u542b\u7531 5 \u6216 6 \u4e2a\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\u6216\u661f\u53f7\u7ec4\u6210\u7684\u7ec4\u3002<\/li>\n<li>$: \u786e\u4fdd\u5e8f\u5217\u7684\u7ed3\u5c3e\u4e0e\u6a21\u5f0f\u5339\u914d\u3002<\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u9a8c\u8bc1\u4e00\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>input_string = \"1 2 3 4 * 6\"\nresult = check_format(input_string)\nprint(result)  # True\n\ninput_string = \"12345\"\nresult = check_format(input_string)\nprint(result)  # False<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f \u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   win10\u7cfb\u7edf\u600e\u4e48\u8bbe\u7f6e\u9000\u51fa\u65f6\u6e05\u9664\u6587\u6863\u6253\u5f00\u5386\u53f2\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u957f\u5ea6\u4e3a6\u81f37\u4f4d\u7684\u6570\u5b57\u6216\u661f\u53f7\u5e8f\u5217\uff1f \u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u5339\u914d\u7279\u5b9a\u683c\u5f0f\u7684\u6570\u5b57\u5e8f\u5217 \u8981\u6c42\u5339\u914d\u4e00\u7ec4\u7531\u7a7a\u683c\u5206\u9694\u5f00\u7684\u6570\u5b57\u5e8f\u5217\uff0c\u9650\u5b9a\u6761\u4ef6\u5982\u4e0b\uff1a \u957f\u5ea6\u4e3a 6 \u81f3 7 \u4f4d \u53ea\u80fd\u5305\u542b\u6570\u5b57\u6216\u661f\u53f7\uff08*\uff09 \u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u51b3\u65b9\u6848 \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Python \u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5757\u8fdb\u884c\u5339\u914d\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u9a8c\u8bc1\u4e0a\u8ff0\u683c\u5f0f\uff1a import re def check_format(input_string): # \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d 6 \u6216 7 \u4e2a\u7531\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\u6216\u661f\u53f7 pattern = r&#8217;^(\\d|\\*)+(\\s(\\d|\\*)+){5,6}$&#8217; match = re.fullmatch(pattern, input_string) return match is not None \u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u9010\u4e00\u5206\u89e3\u5982\u4e0b\uff1a ^(\\d|\\*)+: \u5e8f\u5217\u7684\u5f00\u5934\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u6216\u661f\u53f7\u3002 (\\s(\\d|\\*)+){5,6}: \u5e8f\u5217\u5305\u542b\u7531 5 \u6216 6 \u4e2a\u7a7a\u683c\u5206\u9694\u7684\u6570\u5b57\u6216\u661f\u53f7\u7ec4\u6210\u7684\u7ec4\u3002 $: \u786e\u4fdd\u5e8f\u5217\u7684\u7ed3\u5c3e\u4e0e\u6a21\u5f0f\u5339\u914d\u3002 \u7528\u6cd5\u793a\u4f8b \u8981\u9a8c\u8bc1\u4e00\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a input_string = &#8220;1 2 3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52751","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52751"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52751\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}