{"id":1002688,"date":"2024-12-27T10:10:46","date_gmt":"2024-12-27T02:10:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1002688.html"},"modified":"2024-12-27T10:10:49","modified_gmt":"2024-12-27T02:10:49","slug":"python%e7%9a%84re%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1002688.html","title":{"rendered":"python\u7684re\u5982\u4f55\u5b89\u88c5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080327\/76870968-1c1b-42f8-b85f-fab25cbbe825.webp\" alt=\"python\u7684re\u5982\u4f55\u5b89\u88c5\" \/><\/p>\n<p><p> <strong>Python\u7684re\u6a21\u5757\u65e0\u9700\u5b89\u88c5\u3001\u56e0\u4e3a\u5b83\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\u3001\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u3002<\/strong> \u53ea\u9700\u4f7f\u7528<code>import re<\/code>\u5373\u53ef\u4f7f\u7528re\u6a21\u5757\u63d0\u4f9b\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u529f\u80fd\u3002\u5728Python\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u5904\u7406\u5b57\u7b26\u4e32\u548c\u6587\u672c\u6570\u636e\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u4f7f\u5f97\u6587\u672c\u5339\u914d\u3001\u641c\u7d22\u548c\u66ff\u6362\u53d8\u5f97\u7b80\u5355\u9ad8\u6548\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528re\u6a21\u5757\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5e38\u89c1\u7684\u7528\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001RE\u6a21\u5757\u7b80\u4ecb<\/p>\n<\/p>\n<p><p>Python\u7684re\u6a21\u5757\u662f\u7528\u4e8e\u5904\u7406\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6807\u51c6\u5e93\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5728\u6240\u6709Python\u5b89\u88c5\u4e2d\u90fd\u53ef\u7528\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u6a21\u5f0f\u5339\u914d\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u641c\u7d22\u3001\u5339\u914d\u548c\u64cd\u4f5c\u5b57\u7b26\u4e32\u3002\u901a\u8fc7\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u6587\u672c\u5904\u7406\u4efb\u52a1\uff0c\u5982\u9a8c\u8bc1\u8f93\u5165\u3001\u89e3\u6790\u6570\u636e\u548c\u66ff\u6362\u6587\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u57fa\u672c\u7528\u6cd5<\/li>\n<\/ol>\n<p><p>\u8981\u4f7f\u7528re\u6a21\u5757\uff0c\u4f60\u9996\u5148\u9700\u8981\u5c06\u5176\u5bfc\u5165\u5230\u4f60\u7684Python\u811a\u672c\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5bfc\u5165re\u6a21\u5757\u5e76\u4f7f\u7528\u5b83\u8fdb\u884c\u5b57\u7b26\u4e32\u5339\u914d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>pattern = r&#39;\\bhello\\b&#39;<\/p>\n<p>text = &#39;hello world, hello Python&#39;<\/p>\n<p>matches = re.findall(pattern, text)<\/p>\n<p>print(matches)  # \u8f93\u51fa: [&#39;hello&#39;, &#39;hello&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>re.findall()<\/code>\u51fd\u6570\u7528\u4e8e\u67e5\u627e\u6240\u6709\u5339\u914d\u7684\u5b50\u4e32\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5e38\u7528\u51fd\u6570<\/li>\n<\/ol>\n<ul>\n<li><strong>re.match()<\/strong>: \u4ece\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\u5f00\u59cb\u5339\u914d\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u5982\u679c\u5339\u914d\u6210\u529f\uff0c\u8fd4\u56de\u4e00\u4e2a\u5339\u914d\u5bf9\u8c61\uff1b\u5426\u5219\u8fd4\u56deNone\u3002<\/li>\n<li><strong>re.search()<\/strong>: \u626b\u63cf\u6574\u4e2a\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de\u7b2c\u4e00\u4e2a\u6210\u529f\u5339\u914d\u7684\u7ed3\u679c\u3002<\/li>\n<li><strong>re.findall()<\/strong>: \u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u975e\u91cd\u53e0\u5339\u914d\u7684\u5217\u8868\u3002<\/li>\n<li><strong>re.sub()<\/strong>: \u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5339\u914d\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u90e8\u5206\u3002<\/li>\n<\/ul>\n<p><p>\u4e8c\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u57fa\u7840<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6838\u5fc3\u662f\u6a21\u5f0f\uff0c\u8fd9\u4e9b\u6a21\u5f0f\u53ef\u4ee5\u662f\u5b57\u7b26\u3001\u6570\u5b57\u3001\u7b26\u53f7\u6216\u5b83\u4eec\u7684\u7ec4\u5408\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u8bed\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5b57\u7b26\u7c7b<\/li>\n<\/ol>\n<ul>\n<li><strong>[abc]<\/strong>: \u5339\u914d\u65b9\u62ec\u53f7\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/li>\n<li><strong>[^abc]<\/strong>: \u5339\u914d\u4e0d\u5728\u65b9\u62ec\u53f7\u4e2d\u7684\u5b57\u7b26\u3002<\/li>\n<li><strong>[a-z]<\/strong>: \u5339\u914d\u5c0f\u5199\u5b57\u6bcd\u3002<\/li>\n<li><strong>[0-9]<\/strong>: \u5339\u914d\u6570\u5b57\u3002<\/li>\n<\/ul>\n<ol start=\"2\">\n<li>\u5143\u5b57\u7b26<\/li>\n<\/ol>\n<ul>\n<li><strong>.<\/strong>: \u5339\u914d\u9664\u6362\u884c\u7b26\u4ee5\u5916\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/li>\n<li><strong>\\d<\/strong>: \u5339\u914d\u4efb\u4f55\u6570\u5b57\uff0c\u7b49\u4ef7\u4e8e[0-9]\u3002<\/li>\n<li><strong>\\D<\/strong>: \u5339\u914d\u4efb\u4f55\u975e\u6570\u5b57\u5b57\u7b26\u3002<\/li>\n<li><strong>\\s<\/strong>: \u5339\u914d\u4efb\u4f55\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u5236\u8868\u7b26\u548c\u6362\u884c\u7b26\u3002<\/li>\n<li><strong>\\S<\/strong>: \u5339\u914d\u4efb\u4f55\u975e\u7a7a\u767d\u5b57\u7b26\u3002<\/li>\n<li><strong>\\w<\/strong>: \u5339\u914d\u4efb\u4f55\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\uff0c\u7b49\u4ef7\u4e8e[a-zA-Z0-9_]\u3002<\/li>\n<li><strong>\\W<\/strong>: \u5339\u914d\u4efb\u4f55\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<p><p>\u4e09\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u9ad8\u7ea7\u7528\u6cd5<\/p>\n<\/p>\n<ol>\n<li>\u5206\u7ec4\u4e0e\u547d\u540d<\/li>\n<\/ol>\n<p><p>\u5206\u7ec4\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u4e00\u9879\u91cd\u8981\u529f\u80fd\uff0c\u5b83\u5141\u8bb8\u4f60\u5c06\u591a\u4e2a\u5b57\u7b26\u7ec4\u5408\u6210\u4e00\u4e2a\u5355\u5143\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5c0f\u62ec\u53f7<code>()<\/code>\u6765\u521b\u5efa\u5206\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pattern = r&#39;(hello) world&#39;<\/p>\n<p>text = &#39;hello world, hello Python&#39;<\/p>\n<p>match = re.search(pattern, text)<\/p>\n<p>if match:<\/p>\n<p>    print(match.group(1))  # \u8f93\u51fa: hello<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>group(1)<\/code>\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5206\u7ec4\u5339\u914d\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u524d\u77bb\u4e0e\u540e\u987e<\/li>\n<\/ol>\n<p><p>\u524d\u77bb\u548c\u540e\u987e\u662f\u4e00\u79cd\u96f6\u5bbd\u5ea6\u65ad\u8a00\uff0c\u7528\u4e8e\u5728\u4e0d\u6d88\u8017\u5b57\u7b26\u7684\u60c5\u51b5\u4e0b\u5339\u914d\u7279\u5b9a\u7684\u6761\u4ef6\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>(?=&#8230;)<\/strong>: \u6b63\u5411\u524d\u77bb\uff0c\u5339\u914d&#8230;\u524d\u9762\u7684\u4f4d\u7f6e\u3002<\/li>\n<li><strong>(?&lt;=&#8230;)<\/strong>: \u6b63\u5411\u540e\u987e\uff0c\u5339\u914d&#8230;\u540e\u9762\u7684\u4f4d\u7f6e\u3002<\/li>\n<li><strong>(?!&#8230;)<\/strong>: \u8d1f\u5411\u524d\u77bb\uff0c\u5339\u914d\u4e0d\u5728&#8230;\u524d\u9762\u7684\u4f4d\u7f6e\u3002<\/li>\n<li><strong>(?&lt;!&#8230;)<\/strong>: \u8d1f\u5411\u540e\u987e\uff0c\u5339\u914d\u4e0d\u5728&#8230;\u540e\u9762\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">pattern = r&#39;(?&lt;=\\b)world(?=\\b)&#39;<\/p>\n<p>text = &#39;hello world, hello worlds&#39;<\/p>\n<p>matches = re.findall(pattern, text)<\/p>\n<p>print(matches)  # \u8f93\u51fa: [&#39;world&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u975e\u5e38\u5e7f\u6cdb\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6570\u636e\u9a8c\u8bc1<\/li>\n<\/ol>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u4e8e\u9a8c\u8bc1\u6570\u636e\u683c\u5f0f\uff0c\u5982\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3001\u7535\u8bdd\u53f7\u7801\u548c\u90ae\u653f\u7f16\u7801\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">em<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l_pattern = r&#39;^\\w+@\\w+\\.\\w+$&#39;<\/p>\n<p>email = &#39;example@example.com&#39;<\/p>\n<p>if re.match(email_pattern, email):<\/p>\n<p>    print(&quot;Valid email address&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Invalid email address&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6587\u672c\u641c\u7d22\u4e0e\u66ff\u6362<\/li>\n<\/ol>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u4e8e\u5728\u6587\u672c\u4e2d\u641c\u7d22\u7279\u5b9a\u7684\u6a21\u5f0f\uff0c\u5e76\u8fdb\u884c\u66ff\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &#39;The quick brown fox jumps over the lazy dog&#39;<\/p>\n<p>replaced_text = re.sub(r&#39;\\bfox\\b&#39;, &#39;cat&#39;, text)<\/p>\n<p>print(replaced_text)  # \u8f93\u51fa: The quick brown cat jumps over the lazy dog<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u65e5\u5fd7\u89e3\u6790<\/li>\n<\/ol>\n<p><p>\u5728\u65e5\u5fd7\u5206\u6790\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u4e8e\u89e3\u6790\u548c\u63d0\u53d6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">log = &#39;127.0.0.1 - - [01\/Jan\/2022:00:00:01 +0000] &quot;GET \/index.html HTTP\/1.1&quot; 200 1024&#39;<\/p>\n<p>log_pattern = r&#39;(\\d+\\.\\d+\\.\\d+\\.\\d+) - - \\[(.*?)\\] &quot;(.*?)&quot; (\\d+) (\\d+)&#39;<\/p>\n<p>match = re.match(log_pattern, log)<\/p>\n<p>if match:<\/p>\n<p>    ip, datetime, request, status, size = match.groups()<\/p>\n<p>    print(f&#39;IP: {ip}, DateTime: {datetime}, Request: {request}, Status: {status}, Size: {size}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u4f18\u5316\u6b63\u5219\u8868\u8fbe\u5f0f\u6027\u80fd<\/p>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u867d\u7136\u5f3a\u5927\uff0c\u4f46\u4e0d\u5f53\u7684\u4f7f\u7528\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f18\u5316\u6b63\u5219\u8868\u8fbe\u5f0f\u6027\u80fd\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u907f\u514d\u4f7f\u7528\u8d2a\u5a6a\u5339\u914d<\/li>\n<\/ol>\n<p><p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u8d2a\u5a6a\u7684\uff0c\u4f1a\u5339\u914d\u5c3d\u53ef\u80fd\u591a\u7684\u5b57\u7b26\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u91cf\u8bcd\u540e\u52a0\u4e0a<code>?<\/code>\u6765\u5b9e\u73b0\u975e\u8d2a\u5a6a\u5339\u914d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &#39;&lt;tag&gt;content&lt;\/tag&gt;&lt;tag&gt;another&lt;\/tag&gt;&#39;<\/p>\n<p>pattern = r&#39;&lt;tag&gt;.*?&lt;\/tag&gt;&#39;<\/p>\n<p>matches = re.findall(pattern, text)<\/p>\n<p>print(matches)  # \u8f93\u51fa: [&#39;&lt;tag&gt;content&lt;\/tag&gt;&#39;, &#39;&lt;tag&gt;another&lt;\/tag&gt;&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u63d0\u524d\u7ed3\u675f\u641c\u7d22<\/li>\n<\/ol>\n<p><p>\u5f53\u53ea\u9700\u8981\u7b2c\u4e00\u4e2a\u5339\u914d\u7ed3\u679c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>re.search()<\/code>\u800c\u4e0d\u662f<code>re.findall()<\/code>\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32<\/li>\n<\/ol>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\uff08\u4ee5<code>r<\/code>\u4e3a\u524d\u7f00\uff09\u53ef\u4ee5\u907f\u514d\u53cd\u659c\u6760\u8f6c\u4e49\uff0c\u63d0\u9ad8\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Python\u7684re\u6a21\u5757\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u529f\u80fd\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u6587\u672c\u5904\u7406\u4efb\u52a1\u3002\u901a\u8fc7\u5b66\u4e60\u548c\u638c\u63e1\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u548c\u6280\u5de7\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u9ad8\u6548\u5730\u89e3\u51b3\u590d\u6742\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u95ee\u9898\u3002\u5728\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u6ce8\u610f\u6027\u80fd\u4f18\u5316\u548c\u4ee3\u7801\u53ef\u8bfb\u6027\uff0c\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u9ad8\u6548\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5re\u6a21\u5757\uff1f<\/strong><br \/>re\u6a21\u5757\u662fPython\u7684\u6807\u51c6\u5e93\u4e4b\u4e00\uff0c\u901a\u5e38\u5728\u5b89\u88c5Python\u65f6\u5df2\u7ecf\u9ed8\u8ba4\u5305\u542b\uff0c\u65e0\u9700\u5355\u72ec\u5b89\u88c5\u3002\u5982\u679c\u60a8\u5df2\u5b89\u88c5Python\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165re\u6a21\u5757\u8fdb\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528re\u6a21\u5757\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u6211\u5b89\u88c5\u7684Python\u7248\u672c\u662f\u6700\u65b0\u7684\uff1f<\/strong><br \/>\u8981\u786e\u4fdd\u60a8\u4f7f\u7528\u7684Python\u7248\u672c\u662f\u6700\u65b0\u7684\uff0c\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u3002\u901a\u8fc7\u8fd0\u884c\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u5982\u679c\u9700\u8981\u66f4\u65b0\uff0c\u5efa\u8bae\u5907\u4efd\u60a8\u7684\u9879\u76ee\u6587\u4ef6\uff0c\u5e76\u6309\u7167\u8bf4\u660e\u8fdb\u884c\u66f4\u65b0\u3002<\/p>\n<p><strong>re\u6a21\u5757\u7684\u5e38\u7528\u529f\u80fd\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>re\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u529f\u80fd\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a\u6a21\u5f0f\u5339\u914d\u3001\u641c\u7d22\u5b57\u7b26\u4e32\u3001\u66ff\u6362\u5185\u5bb9\u3001\u5206\u5272\u5b57\u7b26\u4e32\u7b49\u3002\u901a\u8fc7\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u6267\u884c\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5904\u7406\u4efb\u52a1\uff0c\u4f8b\u5982\u9a8c\u8bc1\u7535\u5b50\u90ae\u4ef6\u683c\u5f0f\u3001\u63d0\u53d6\u7279\u5b9a\u6570\u636e\u7b49\u3002\u5e38\u7528\u7684\u51fd\u6570\u5305\u62ec<code>re.match()<\/code>\u3001<code>re.search()<\/code>\u3001<code>re.sub()<\/code>\u548c<code>re.findall()<\/code>\uff0c\u5b83\u4eec\u5404\u81ea\u7528\u4e8e\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u5339\u914d\u548c\u5904\u7406\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u7684re\u6a21\u5757\u65e0\u9700\u5b89\u88c5\u3001\u56e0\u4e3a\u5b83\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\u3001\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u3002 \u53ea\u9700\u4f7f\u7528im [&hellip;]","protected":false},"author":3,"featured_media":1002696,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002688"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1002688"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002688\/revisions"}],"predecessor-version":[{"id":1002697,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002688\/revisions\/1002697"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1002696"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1002688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1002688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1002688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}