{"id":134,"date":"2022-01-25T22:21:44","date_gmt":"2022-01-25T14:21:44","guid":{"rendered":"https:\/\/www.daogu.work\/?p=134"},"modified":"2022-01-25T22:27:33","modified_gmt":"2022-01-25T14:27:33","slug":"%e7%94%a8python%e6%ad%a3%e5%88%99%e7%b2%be%e7%a1%ae%e5%8c%b9%e9%85%8d11%e4%bd%8d%e6%95%b0%e5%ad%97","status":"publish","type":"post","link":"https:\/\/daogu.work\/?p=134","title":{"rendered":"\u7528python\u6b63\u5219\u7cbe\u786e\u5339\u914d11\u4f4d\u6570\u5b57"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u95ee\u9898\u80cc\u666f<\/h2>\n\n\n\n<p>\u53d6\u4e00\u6bb5\u6587\u672c\u4e2d\u7684\u6240\u670911\u4f4d\u6570\u5b57\uff0c\u4f30\u4e14\u53ef\u4ee5\u7406\u89e3\u6210\u624b\u673a\u53f7\u5427\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5177\u4f53\u8981\u6c42<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>11\u4f4d\u6570\u5b57<\/li><li>8\u4f4d\u7684\uff0c\u8d85\u8fc711\u4f4d\u7684\u90fd\u4e0d\u7b97<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u95ee\u9898\u53d8\u66f4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b63\u5219\u7f51\u7ad9\u6d4b\u8bd5\u6b63\u5e38<\/h3>\n\n\n\n<p>\u5728\u4e00\u4e2a\u7f51\u7ad9\u4e0a<a href=\"https:\/\/regex101.com\/\">regex101<\/a>\u505a\u597d\u7684\u624b\u673a\u53f7\u7684\u8bc6\u522b\uff0c\u5927\u5bb6\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u81ea\u5df1\u53bb\u8bd5\u4e00\u8bd5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.daogu.work\/images\/2022\/01\/25\/chrome_Tjtp3F9bfc.png\" alt=\"chrome_Tjtp3F9bfc.png\"\/><\/figure>\n\n\n\n<p>\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>12345678901\na12345678901\n12345678901bb\na12345678901bb\n18274877543aa<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">python\u6d4b\u8bd5\u5931\u8d25<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import re\nre.findall(\"(?&lt;=&#91;^\\d])&#91;12]{2}(?=&#91;^\\d])\",\"12abc12\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u67e5\u627e2\u4f4d\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>re.findall(\"&#91;12]{2}\",\"12abc12\")\nOut&#91;5]: &#91;'12', '12']<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5305\u542b3\u4f4d\u6570\u5931\u6548<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>re.findall(\"&#91;12]{2}\",\"12abc123\")\nOut&#91;6]: &#91;'12', '12']<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u5176\u5b9e\u53ea\u60f3\u8981\u7279\u5b9a\u4f4d\u6570\u7684\uff0c\u8fd9\u91cc\u5e94\u8be5\u53ea\u8fd4\u56de12\u5373\u53ef\uff0c\u540e\u9762\u90a3\u4e2a123\u4e2d\u768412\u4e0d\u5e94\u8be5\u88ab\u63d0\u53d6\u51fa\u6765\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u770b\u6b63\u5e38\u7684\u6b63\u5219\u4ee3\u7801\u5728python\u91cc\u9762\u7684\u8868\u73b0<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import re\nmobile = &#91;\"12345678901\", \"a12345678901\", \"12345678901bb\", \"a12345678901bb\",\"18274877543aa\"]\n\ndef regmobile(mobile):\n    pattern = \"(?&lt;=&#91;^\\d])1&#91;0-9]{10}(?=&#91;^\\d])\"\n    return re.findall(pattern,mobile)\n&#91;regmobile(x) for x in mobile]\nOut&#91;12]: &#91;&#91;], &#91;], &#91;], &#91;'12345678901'], &#91;]]\n<\/code><\/pre>\n\n\n\n<p>\u770b\u5230\u53ea\u5339\u914d\u4e86\u7b2c4\u4e2a\uff0c\u5176\u4f59\u7684\u4e00\u4e2a\u90fd\u6ca1\u6709\u547d\u4e2d\uff0c\u4f46\u662f\u5728\u6211\u4eec\u7ec3\u4e60\u7684\u7f51\u7ad9\u4e0a\uff0c\u662f\u5168\u90e8\u5339\u914d\u6210\u529f\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u51b3\u65b9\u6848<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u95ee\u9898\u539f\u56e0<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>python\u4e2d\u7684look behind\u662f\u8981\u6709\u56fa\u5b9a\u7684\u957f\u5ea6\u7684\uff0c\u6240\u4ee5\u6ca1\u529e\u6cd5\u5339\u914d\u7a7a\u503c\u7684\u4f8b\u5b50\uff0c\u6bd4\u5982mobile\u4e2d\u7684<code>12345678901<\/code>\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u51b3\u529e\u6cd5<\/h3>\n\n\n\n<p><code>reg = re.compile(r\"(?:^|(?&lt;=[^\\d]))1[0-9]{10}(?=[^0-9]|$)\")<\/code><\/p>\n\n\n\n<p>\u7ed3\u5408<code>^<\/code>\u548c<code>$<\/code>\u8fd9\u4e24\u4e2a\u7b26\u53f7\u53ef\u4ee5\u89e3\u51b3\u96f6\u5bbd\u65ad\u8a00\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca\u4e00\u4e0bre.compile\u4ec0\u4e48\u610f\u601d<\/h4>\n\n\n\n<p>\u5c31\u662f\u628a\u6b63\u5219\u7684\u8bed\u53e5\u63d0\u524d\u7f16\u8bd1\u4e00\u4e0b\uff0c\u518d\u67e5\u627e\u8d77\u6765\u4f1a\u5feb\u5f88\u591a\u3002\u76f8\u5f53\u4e8e\u5bf9re\u53c8\u8d77\u4e86\u4e00\u4e2a\u5b9e\u4f8b\u3002<br>\u7528\u6cd5\u5982\u4e0b\uff1a<br><code>reg.findall(mobile)<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u76f8\u4f3c\u95ee\u9898<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u63d0\u53d6\u53ea\u67094-6\u4f4d\u7684\u6570\u5b57\u9a8c\u8bc1\u7801\uff1f<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u95ee\u9898\u6709\u6548\u6574\u7406\u6210\uff0c\u5982\u4f55\u5229\u7528tasker\u81ea\u52a8\u8f6c\u53d1\u77ed\u4fe1\u9a8c\u8bc1\u7801\uff1f<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u901a\u8fc7m1\u7535\u8111\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7bark\u5728\u7184\u5c4f\u65f6\u81ea\u52a8\u63a8\u9001\u5230PC\u7aef\u3002(\u5927\u5927\u63d0\u5347PC\u7aef\u4f7f\u7528\u9a8c\u8bc1\u7801\u627e\u624b\u673a\u7684\u7528\u6237\u4f53\u9a8c\u54c8)<\/li><li>\u591a\u53f0\u624b\u673a\u7684\u9a8c\u8bc1\u7801\u8f6c\u53d1\u3002\u51c6\u786e\u8bc6\u522b\u51fa\u9a8c\u8bc1\u7801\u53ef\u4ee5\u89e3\u51b3\u51fa\u5f88\u591a\u95ee\u9898\u3002<\/li><li>\u81ea\u52a8\u5145\u503c\u7684\u793c\u54c1\u5361\u5bc6\u94a5\uff0c\u6536\u5230\u597d\u81ea\u52a8\u590d\u5236\u5230\u526a\u8d34\u677f\uff0c\u7136\u540e\u5e76\u81ea\u52a8\u6253\u5f00\u8981\u5145\u503c\u7684APP\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u53c2\u8003\u8d44\u6599<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/www.coder.work\/article\/7276184\" target=\"_blank\" rel=\"noreferrer noopener\">regex &#8211; Python \u6b63\u5219\u8868\u8fbe\u5f0f\u9519\u8bef<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/58310184\/python-regex-error-look-behind-requires-fixed-width-pattern\" target=\"_blank\" rel=\"noreferrer noopener\">Python regex error: look-behind requires fixed-width pattern<\/a><\/li><li><a href=\"http:\/\/www.talkstats.com\/threads\/python-regex-fixed-width-positive-lookbehinds.72426\/\" target=\"_blank\" rel=\"noreferrer noopener\">[Python] regex fixed-width positive lookbehinds \u2013 \u62a5\u9519\u5e38\u89c1\u5f62\u5f0f<\/a><\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u80cc\u666f \u53d6\u4e00\u6bb5\u6587\u672c\u4e2d\u7684\u6240\u670911\u4f4d\u6570\u5b57\uff0c\u4f30\u4e14\u53ef\u4ee5\u7406\u89e3\u6210\u624b\u673a\u53f7\u5427\u3002 \u5177\u4f53\u8981\u6c42 11\u4f4d\u6570\u5b57 8\u4f4d\u7684\uff0c\u8d85\u8fc711\u4f4d\u7684\u90fd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,26,25],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-unclassified","tag-python","tag-26","tag-25"],"_links":{"self":[{"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daogu.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":2,"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":142,"href":"https:\/\/daogu.work\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions\/142"}],"wp:attachment":[{"href":"https:\/\/daogu.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daogu.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daogu.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}