{"id":49745,"date":"2024-12-03T11:33:06","date_gmt":"2024-12-03T03:33:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49745\/"},"modified":"2024-12-03T11:33:06","modified_gmt":"2024-12-03T03:33:06","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%90%88%e5%b9%b6%e5%a4%9a%e8%a1%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%b9%b6%e4%bf%9d%e7%95%99%e7%89%b9%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49745\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241102\/17305405616725f4111ee12.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python \u6309\u8981\u6c42\u5408\u5e76\u590d\u6742\u7684\u591a\u884c\u5b57\u7b26\u4e32<\/strong><\/p>\n<p>\u60f3\u8981\u6839\u636e\u7279\u5b9a\u89c4\u5219\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\uff0c\u63d0\u793a\u8981\u6c42\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u4fdd\u7559\u53e5\u53f7\u3001\u611f\u53f9\u53f7\u540e\u9762\u7684\u6362\u884c\u3002<\/li>\n<li>\u4fdd\u7559 1\u30012\u3001\u7b49\u6570\u5b57\u524d\u9762\u7684\u6362\u884c\u3002<\/li>\n<li>\u5408\u5e76\u5176\u4ed6\u6240\u6709\u7684\u6362\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<pre>print(re.sub(r'(?&amp;lt;![\u3002\uff01])\\r?\\n(?!\\d+\u3001)', '', text))<\/pre>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f (?&lt;![\u3002\uff01])r?n(?!d+\u3001) \u5728\u4ee5\u4e0b\u60c5\u51b5\u5339\u914d\u6362\u884c\u7b26\uff1a<\/p>\n<ul>\n<li>(?&lt;![\u3002\uff01])\uff1a\u786e\u4fdd\u5339\u914d\u7684\u6362\u884c\u7b26\u4e0d\u4f4d\u4e8e\u53e5\u53f7\u6216\u611f\u53f9\u53f7\u4e4b\u540e\u3002<\/li>\n<li>r?n\uff1a\u5339\u914d\u4efb\u4f55\u7c7b\u578b\u7684\u6362\u884c\u7b26\uff08crlf \u6216 lf\uff09\u3002<\/li>\n<li>(?!d+\u3001)\uff1a\u786e\u4fdd\u5339\u914d\u7684\u6362\u884c\u7b26\u4e0d\u4f4d\u4e8e\u6570\u5b57\u548c\u4e2d\u6587\u9017\u53f7\u201c\u3001\u201d\u4e4b\u524d\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u4fdd\u7559\u6ee1\u8db3\u8fd9\u4e9b\u6761\u4ef6\u7684\u6362\u884c\u7b26\uff0c\u5e76\u7528\u7a7a\u5b57\u7b26\u4e32\u66ff\u6362\u6240\u6709\u5176\u4ed6\u6362\u884c\u7b26\uff0c\u4ece\u800c\u5b9e\u73b0\u8981\u6c42\u7684\u5b57\u7b26\u4e32\u5408\u5e76\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 python \u6309\u8981\u6c42\u5408\u5e76\u590d\u6742\u7684\u591a\u884c\u5b57\u7b26\u4e32 \u60f3\u8981\u6839\u636e\u7279\u5b9a\u89c4\u5219\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\uff0c\u63d0\u793a\u8981\u6c42\u5982\u4e0b\uff1a \u4fdd\u7559\u53e5\u53f7\u3001\u611f\u53f9\u53f7\u540e\u9762\u7684\u6362\u884c\u3002 \u4fdd\u7559 1\u30012\u3001\u7b49\u6570\u5b57\u524d\u9762\u7684\u6362\u884c\u3002 \u5408\u5e76\u5176\u4ed6\u6240\u6709\u7684\u6362\u884c\u3002 \u89e3\u51b3\u65b9\u6848\uff1a print(re.sub(r'(?&amp;lt;![\u3002\uff01])\\r?\\n(?!\\d+\u3001)&#8217;, &#8221;, text)) \u89e3\u91ca\uff1a \u6b63\u5219\u8868\u8fbe\u5f0f (?&lt;![\u3002\uff01])r?n(?!d+\u3001) \u5728\u4ee5\u4e0b\u60c5\u51b5\u5339\u914d\u6362\u884c\u7b26\uff1a (?&lt;![\u3002\uff01])\uff1a\u786e\u4fdd\u5339\u914d\u7684\u6362\u884c\u7b26\u4e0d\u4f4d\u4e8e\u53e5\u53f7\u6216\u611f\u53f9\u53f7\u4e4b\u540e\u3002 r?n\uff1a\u5339\u914d\u4efb\u4f55\u7c7b\u578b\u7684\u6362\u884c\u7b26\uff08crlf \u6216 lf\uff09\u3002 (?!d+\u3001)\uff1a\u786e\u4fdd\u5339\u914d\u7684\u6362\u884c\u7b26\u4e0d\u4f4d\u4e8e\u6570\u5b57\u548c\u4e2d\u6587\u9017\u53f7\u201c\u3001\u201d\u4e4b\u524d\u3002 \u56e0\u6b64\uff0c\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u4fdd\u7559\u6ee1\u8db3\u8fd9\u4e9b\u6761\u4ef6\u7684\u6362\u884c\u7b26\uff0c\u5e76\u7528\u7a7a\u5b57\u7b26\u4e32\u66ff\u6362\u6240\u6709\u5176\u4ed6\u6362\u884c\u7b26\uff0c\u4ece\u800c\u5b9e\u73b0\u8981\u6c42\u7684\u5b57\u7b26\u4e32\u5408\u5e76\u3002 \u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 Python \u6b63\u5219\u8868\u8fbe\u5f0f\u5408\u5e76\u591a\u884c\u5b57\u7b26\u4e32\u5e76\u4fdd\u7559\u7279\u5b9a\u6362\u884c\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/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-49745","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49745","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=49745"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49745\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}