{"id":204388,"date":"2025-05-29T14:41:41","date_gmt":"2025-05-29T06:41:41","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204388\/"},"modified":"2025-05-29T14:41:41","modified_gmt":"2025-05-29T06:41:41","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e4%b8%ad%e7%9a%84-re-split-%e5%87%bd%e6%95%b0%e6%a0%b9%e6%8d%ae%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%88%86%e5%89%b2%e5%8c%85%e5%90%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204388\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u4e2d\u7684 `re.split()` \u51fd\u6570\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5305\u542b\u62ec\u53f7\u7684\u5b57\u7b26\u4e32\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u4e2d\u7684 `re.split()` \u51fd\u6570\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5305\u542b\u62ec\u53f7\u7684\u5b57\u7b26\u4e32\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u4f7f\u7528 Python \u4e2d\u7684 `re.split()` \u51fd\u6570\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5305\u542b\u62ec\u53f7\u7684\u5b57\u7b26\u4e32\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241106\/1730876629672b14d56e775.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u7406\u89e3 re.split<\/strong><\/p>\n<p>python \u4e2d\u7684 re.split() \u51fd\u6570\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7ed3\u679c\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u5b50\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u95ee\u9898\u89e3\u6790<\/strong><\/p>\n<p>\u4ee3\u7801 re.split(r&#8221;,(?![^(]*))&#8221;, a) \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f ,(?![^(]*)) \u6765\u5206\u5272\u5b57\u7b26\u4e32 a\u3002\u8fd9\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u9017\u53f7\uff0c\u4f46\u6392\u9664\u5305\u542b\u62ec\u53f7\u548c\u62ec\u53f7\u5185\u7684\u4efb\u610f\u5b57\u7b26\u7684\u5339\u914d\u3002<\/p>\n<p><strong>\u7b54\u6848\u89e3\u91ca<\/strong><\/p>\n<p>\u6b64\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5de5\u4f5c\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p>,(?![( ]*))`<\/p>\n<ul>\n<li>\u5339\u914d\u9017\u53f7 (,)\u3002<\/li>\n<li>(?![( ]*)) \u662f\u4e00\u4e2a\u5426\u5b9a\u5148\u884c\u65ad\u8a00\uff0c\u5b83\u786e\u4fdd\u5f53\u524d\u5339\u914d\u7684\u9017\u53f7\u4e0d\u4f4d\u4e8e\u5305\u542b\u62ec\u53f7 ( \u6216 )` \u7684\u5b50\u5b57\u7b26\u4e32\u5185\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u6b64\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u5339\u914d\u6240\u6709\u4e0d\u5c5e\u4e8e\u62ec\u53f7\u5c01\u95ed\u5b50\u5b57\u7b26\u4e32\u7684\u9017\u53f7\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6b64\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre>import re\n\na = \"sfdsf,(sdf),adfsf,sdfsf,(,),\"\nb = re.split(r\" ,(?![^(]*\\))\" , a)\nprint(b)<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>['sfdsf', '(sdf)', 'adfsf', 'sdfsf', '(,)', '']<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 Python \u4e2d\u7684 `re.split()` \u51fd\u6570\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5305\u542b\u62ec\u53f7\u7684\u5b57\u7b26\u4e32\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u4e2d\u7684 `&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204388","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204388"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204388\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}