{"id":1368,"date":"2024-11-05T16:07:19","date_gmt":"2024-11-05T08:07:19","guid":{"rendered":"https:\/\/www.qiangzhenshuai.com\/?p=1368"},"modified":"2024-11-10T23:08:48","modified_gmt":"2024-11-10T15:08:48","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.qiangzhenshuai.com\/?p=1368","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f"},"content":{"rendered":"<h1>1.\u6b63\u5219\u8868\u8fbe\u5f0f\u6982\u8ff0<\/h1>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\uff08Regular Expression\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u5339\u914d\u3001\u67e5\u627e\u548c\u66ff\u6362\u6587\u672c\u4e2d\u7279\u5b9a\u6a21\u5f0f\u7684\u5f3a\u5927\u5de5\u5177\u3002\u5b83\u5728\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u548c\u6587\u672c\u5904\u7406\u5de5\u5177\u4e2d\u90fd\u6709\u5e7f\u6cdb\u5e94\u7528\uff0c\u4ee5\u4e0b\u662f\u5173\u4e8e\u5b83\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n<h2 class=\"header-o0Xpoc auto-hide-last-sibling-br\">\u57fa\u672c\u6982\u5ff5<\/h2>\n<h3>\u5b57\u7b26<\/h3>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7531\u666e\u901a\u5b57\u7b26\uff08\u5982\u5b57\u6bcd\u3001\u6570\u5b57\u7b49\uff09\u548c\u7279\u6b8a\u5b57\u7b26\uff08\u5177\u6709\u7279\u5b9a\u542b\u4e49\u7684\u7b26\u53f7\uff09\u7ec4\u6210\u3002\u666e\u901a\u5b57\u7b26\u6309\u7167\u5176\u5b57\u9762\u610f\u4e49\u8fdb\u884c\u5339\u914d\uff0c\u4f8b\u5982\u5728\u6b63\u5219\u8868\u8fbe\u5f0f \u201cabc\u201d \u4e2d\uff0c\u5c31\u4f1a\u7cbe\u786e\u5339\u914d\u6587\u672c\u4e2d\u7684 \u201cabc\u201d \u8fd9\u4e09\u4e2a\u8fde\u7eed\u5b57\u7b26\u3002<\/p>\n<p>\u666e\u901a\u5b57\u7b26\uff1a\u5982\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u7b49\uff0c\u76f4\u63a5\u5339\u914d\u81ea\u8eab\u3002\u4f8b\u5982\uff0c\u201ca\u201d \u5c06\u5339\u914d\u6587\u672c\u4e2d\u7684 \u201ca\u201d \u5b57\u7b26\u3002<\/p>\n<p>\u7279\u6b8a\u5b57\u7b26\uff1a\u5177\u6709\u7279\u5b9a\u542b\u4e49\u7684\u5b57\u7b26\uff0c\u5982 \u201c.\u201d\u201c*\u201d\u201c+\u201d\u201c?\u201d\u201c\\\u201d \u7b49\u3002<\/p>\n<h3>\u5143\u5b57\u7b26<\/h3>\n<p>\u662f\u5177\u6709\u7279\u6b8a\u542b\u4e49\u7684\u5b57\u7b26\uff0c\u6bd4\u5982 \u201c.\u201d \u53ef\u4ee5\u5339\u914d\u9664\u6362\u884c\u7b26\u4ee5\u5916\u7684\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\uff1b\u201c*\u201d \u8868\u793a\u524d\u9762\u7684\u5b57\u7b26\u53ef\u4ee5\u51fa\u73b0\u96f6\u6b21\u6216\u591a\u6b21\u7b49\u3002\u5e38\u89c1\u7684\u5143\u5b57\u7b26\u8fd8\u6709 \u201c+\u201d\uff08\u524d\u9762\u7684\u5b57\u7b26\u51fa\u73b0\u4e00\u6b21\u6216\u591a\u6b21\uff09\u3001\u201c?\u201d\uff08\u524d\u9762\u7684\u5b57\u7b26\u51fa\u73b0\u96f6\u6b21\u6216\u4e00\u6b21\uff09\u7b49\u3002<\/p>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u5143\u5b57\u7b26<\/h4>\n<p>\u201c.\u201d\uff1a\u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\uff0c\u9664\u4e86\u6362\u884c\u7b26\u3002<br \/>\n\u201c\\d\u201d\uff1a\u5339\u914d\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u3002<br \/>\n\u201c\\w\u201d\uff1a\u5339\u914d\u4e00\u4e2a\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\u5b57\u7b26\u3002<br \/>\n\u201c\\s\u201d\uff1a\u5339\u914d\u4e00\u4e2a\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u884c\u7b26\u7b49\u3002<br \/>\n\u201c^\u201d\uff1a\u8868\u793a\u5339\u914d\u884c\u7684\u5f00\u5934\u3002<br \/>\n\u201c$\u201d\uff1a\u8868\u793a\u5339\u914d\u884c\u7684\u7ed3\u5c3e\u3002<br \/>\n^$\uff1a\u7a7a\u884c<br \/>\n\\D\uff1a\u5339\u914d\u4efb\u4f55\u975e\u6570\u5b57\u5b57\u7b26\u3002<br \/>\n\\W\uff1a\u5339\u914d\u4efb\u4f55\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u3002<br \/>\n\\S\uff1a\u5339\u914d\u4efb\u4f55\u975e\u7a7a\u767d\u5b57\u7b26\u3002<br \/>\n\\b\uff1a\u5339\u914d\u5355\u8bcd\u8fb9\u754c\u3002<br \/>\n\\B\uff1a\u5339\u914d\u975e\u5355\u8bcd\u8fb9\u754c\u3002<\/p>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u91cf\u8bcd<\/h4>\n<p>\u201c*\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u96f6\u6b21\u6216\u591a\u6b21\u3002<br \/>\n\u201c+\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u4e00\u6b21\u6216\u591a\u6b21\u3002<br \/>\n\u201c?\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u96f6\u6b21\u6216\u4e00\u6b21\u3002<br \/>\n\u201c{n}\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u6070\u597d n \u6b21\u3002<br \/>\n\u201c{n,}\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u81f3\u5c11 n \u6b21\u3002<br \/>\n\u201c{n,m}\u201d\uff1a\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u81f3\u5c11 n \u6b21\uff0c\u81f3\u591a m \u6b21\u3002<br \/>\n0{2,5}\uff1a\u9650\u5b9a\u6570\u5b57 \u201c0\u201d \u51fa\u73b0\u7684\u6b21\u6570\u5728 2 \u5230 5 \u6b21\u4e4b\u95f4,\u5728\u5b57\u7b26\u4e32 \u201c000\u201d\u3001\u201c0000\u201d\u3001\u201c00000\u201d \u4e2d\u90fd\u80fd\u5339\u914d\u6210\u529f\uff0c\u800c\u5728 \u201c0\u201d \u6216\u8005 \u201c000000\u201d \u7b49\u60c5\u51b5\u4e0b\u5c31\u53ef\u80fd\u5339\u914d\u5931\u8d25\uff08\u5177\u4f53\u53d6\u51b3\u4e8e\u4f7f\u7528\u573a\u666f\u548c\u5176\u4ed6\u5339\u914d\u6761\u4ef6<br \/>\n[abc]{2}\u53ef\u4ee5\u5339\u914d \u201caa\u201d\u3001\u201cbb\u201d\u3001\u201ccc\u201d\uff0c\u56e0\u4e3a\u5b83\u8868\u793a\u5339\u914d \u201ca\u201d\u3001\u201cb\u201d \u6216 \u201cc\u201d \u91cd\u590d\u4e24\u6b21\u7684\u60c5\u51b5\u3002<br \/>\na{1,3}b\u53ef\u4ee5\u5339\u914d \u201cab\u201d\u3001\u201caab\u201d \u6216 \u201caaab\u201d\uff0c\u56e0\u4e3a\u5b83\u8868\u793a \u201ca\u201d \u91cd\u590d\u4e00\u5230\u4e09\u6b21\uff0c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a \u201cb\u201d<\/p>\n<h4>\u5b57\u7b26\u96c6<\/h4>\n<p>[abc]\u00a0\u5339\u914d\u5305\u542b\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\uff08\u5982 a \u6216 b \u6216 c\uff09\u3002<br \/>\n[^abc]\u00a0\u5339\u914d\u4e0d\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<br \/>\n[a-z]\u00a0\u5339\u914d\u4ece a \u5230 z \u8303\u56f4\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u6bcd\u3002<br \/>\n[A-Z]\u00a0\u5339\u914d\u4ece A \u5230 Z \u8303\u56f4\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u6bcd\u3002<br \/>\n[0-9]\u00a0\u5339\u914d\u4ece 0 \u5230 9 \u8303\u56f4\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u6570\u5b57\u3002<br \/>\n{}\u00a0\u7528\u4e8e\u6307\u5b9a\u524d\u4e00\u4e2a\u5143\u7d20\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u53ef\u4ee5\u662f\u7cbe\u786e\u5339\u914d\u3001\u81f3\u5c11\u5339\u914d\u6216\u8303\u56f4\u5339\u914d\u3002<br \/>\n[]\u00a0\u7528\u4e8e\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u7c7b\uff0c\u5339\u914d\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\uff0c\u53ef\u4ee5\u5305\u62ec\u8303\u56f4\u548c\u5426\u5b9a\u3002<\/p>\n<h4>\u5206\u7ec4\u4e0e\u5f15\u7528<\/h4>\n<p>(ab)\u00a0\u5c06 &#8220;ab&#8221; \u89c6\u4e3a\u4e00\u4e2a\u6574\u4f53\u8fdb\u884c\u5339\u914d\u3002<br \/>\n\\1,\u00a0\\2\u00a0\u7b49\u7b49\uff0c\u5f15\u7528\u4e4b\u524d\u6355\u83b7\u7684\u7ec4\u3002<\/p>\n<h4>\u9009\u62e9<\/h4>\n<p>a|b\u00a0\u5339\u914d a \u6216\u8005 b\u3002<\/p>\n<h4>\u793a\u4f8b<\/h4>\n<p>a.b\u00a0\u53ef\u4ee5\u5339\u914d &#8220;acb&#8221;\uff0c&#8221;a2b&#8221;\uff0c&#8221;a b&#8221; \u7b49\u7b49\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &#8220;ab&#8221;\u3002<br \/>\n^a\u00a0\u53ea\u80fd\u5339\u914d\u4ee5 &#8216;a&#8217; \u5f00\u5934\u7684\u5b57\u7b26\u4e32\u3002<br \/>\nb$\u00a0\u53ea\u80fd\u5339\u914d\u4ee5 &#8216;b&#8217; \u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u3002<br \/>\ncolou?r\u00a0\u53ef\u4ee5\u5339\u914d &#8220;color&#8221; \u6216 &#8220;colour&#8221;\u3002<br \/>\n[0-9]{3}\u00a0\u5339\u914d\u4e09\u4e2a\u8fde\u7eed\u7684\u6570\u5b57\uff0c\u4f8b\u5982 &#8220;123&#8221;\u3002<\/p>\n<h4>\u975e\u8d2a\u5a6a\u5339\u914d<\/h4>\n<p data-spm-anchor-id=\"5176.28103460.0.i10.5e045d27jsTyyv\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u91cf\u8bcd *, +, {n,}, {n,m} \u662f\u8d2a\u5a6a\u7684\uff0c\u610f\u5473\u7740\u5b83\u4eec\u4f1a\u5c3d\u53ef\u80fd\u591a\u5730\u5339\u914d\u5b57\u7b26\u3002\u5982\u679c\u5728\u8fd9\u4e9b\u91cf\u8bcd\u540e\u9762\u52a0\u4e0a ?\uff0c\u5b83\u4eec\u5c31\u4f1a\u53d8\u6210\u975e\u8d2a\u5a6a\u6a21\u5f0f\uff0c\u5373\u5c3d\u53ef\u80fd\u5c11\u5730\u5339\u914d\u5b57\u7b26\u3002<\/p>\n<h4>\u8f6c\u4e49\u5b57\u7b26<\/h4>\n<p>\\\u00a0\u7528\u4e8e\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\uff0c\u4f7f\u5176\u5931\u53bb\u7279\u6b8a\u610f\u4e49\u3002\u4f8b\u5982\uff0c\u8981\u5339\u914d\u70b9\u53f7\u00a0.\uff0c\u9700\u8981\u5199\u6210\u00a0\\.\u3002<\/p>\n<p data-spm-anchor-id=\"5176.28103460.0.i12.5e045d27jsTyyv\">\u6b63\u5219\u8868\u8fbe\u5f0f\u975e\u5e38\u5f3a\u5927\uff0c\u4f46\u4e5f\u53ef\u80fd\u56e0\u4e3a\u8fc7\u4e8e\u590d\u6742\u800c\u96be\u4ee5\u7406\u89e3\u548c\u7ef4\u62a4\u3002\u56e0\u6b64\uff0c\u5728\u7f16\u5199\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u6e05\u6670\u6027\u548c\u7b80\u6d01\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5982\u679c\u4f60\u6709\u7279\u5b9a\u7684\u9700\u6c42\u6216\u95ee\u9898\uff0c\u53ef\u4ee5\u544a\u8bc9\u6211\uff0c\u6211\u4f1a\u5c3d\u529b\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p>\n<h2 class=\"header-o0Xpoc auto-hide-last-sibling-br\">\u5e38\u7528\u8bed\u6cd5<\/h2>\n<p>\u5b57\u7b26\u7c7b\uff1a\u53ef\u4ee5\u7528\u65b9\u62ec\u53f7 \u201c[]\u201d \u6765\u5b9a\u4e49\u5b57\u7b26\u7c7b\uff0c\u5b83\u8868\u793a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982 \u201c[abc]\u201d \u80fd\u5339\u914d \u201ca\u201d\u201cb\u201d \u6216\u8005 \u201cc\u201d\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528\u8303\u56f4\u8868\u793a\uff0c\u5982 \u201c[a-z]\u201d \u53ef\u5339\u914d\u4efb\u610f\u5c0f\u5199\u5b57\u6bcd\u3002<\/p>\n<p>\u91cf\u8bcd\uff1a\u7528\u4e8e\u6307\u5b9a\u524d\u9762\u7684\u5b57\u7b26\u6216\u5b57\u7b26\u7ec4\u51fa\u73b0\u7684\u6b21\u6570\u3002\u9664\u4e86\u524d\u9762\u63d0\u5230\u7684 \u201c*\u201d\u201c+\u201d\u201c?\u201d\uff0c\u8fd8\u6709 \u201c{n}\u201d\uff08\u524d\u9762\u7684\u5b57\u7b26\u6070\u597d\u51fa\u73b0 n \u6b21\uff09\u3001\u201c{n,}\u201d\uff08\u524d\u9762\u7684\u5b57\u7b26\u81f3\u5c11\u51fa\u73b0 n \u6b21\uff09\u3001\u201c{n,m}\u201d\uff08\u524d\u9762\u7684\u5b57\u7b26\u51fa\u73b0\u6b21\u6570\u5728 n \u5230 m \u4e4b\u95f4\uff09\u7b49\u3002<\/p>\n<p>\u5206\u7ec4\uff1a\u7528\u5c0f\u62ec\u53f7 \u201c()\u201d \u53ef\u4ee5\u5c06\u5b57\u7b26\u6216\u5b57\u7b26\u7ec4\u8fdb\u884c\u5206\u7ec4\uff0c\u4ee5\u4fbf\u5bf9\u5206\u7ec4\u5185\u7684\u5185\u5bb9\u8fdb\u884c\u6574\u4f53\u64cd\u4f5c\uff0c\u6bd4\u5982\u91cd\u590d\u3001\u83b7\u53d6\u5339\u914d\u7684\u5b50\u4e32\u7b49\u3002<\/p>\n<h2 class=\"header-o0Xpoc auto-hide-last-sibling-br\">\u5e94\u7528\u573a\u666f<\/h2>\n<h4>\u6587\u672c\u9a8c\u8bc1<\/h4>\n<p>\u5728\u7528\u6237\u6ce8\u518c\u767b\u5f55\u65f6\u9a8c\u8bc1\u8f93\u5165\u7684\u90ae\u7bb1\u5730\u5740\u3001\u7535\u8bdd\u53f7\u7801\u7b49\u683c\u5f0f\u662f\u5426\u6b63\u786e\u3002\u4f8b\u5982\uff0c\u9a8c\u8bc1\u90ae\u7bb1\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u80fd\u662f \u201c^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$\u201d\uff0c\u5b83\u4f1a\u68c0\u67e5\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u5e38\u89c1\u7684\u90ae\u7bb1\u683c\u5f0f\u3002<\/p>\n<h4>\u6587\u672c\u641c\u7d22\u4e0e\u66ff\u6362<\/h4>\n<p>\u5728\u4e00\u7bc7\u957f\u7bc7\u6587\u6863\u4e2d\u5feb\u901f\u67e5\u627e\u7279\u5b9a\u6a21\u5f0f\u7684\u6587\u672c\u5e76\u8fdb\u884c\u66ff\u6362\u3002\u6bd4\u5982\u8981\u5c06\u6587\u6863\u4e2d\u6240\u6709\u7684\u6570\u5b57\u66ff\u6362\u6210 \u201c*\u201d\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5408\u9002\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5b9a\u4f4d\u6570\u5b57\u7136\u540e\u8fdb\u884c\u66ff\u6362\u64cd\u4f5c\u3002<\/p>\n<h4>\u6570\u636e\u63d0\u53d6<\/h4>\n<p>\u4ece\u5927\u91cf\u6587\u672c\u6570\u636e\u4e2d\u63d0\u53d6\u51fa\u7b26\u5408\u7279\u5b9a\u6a21\u5f0f\u7684\u4fe1\u606f\u3002\u6bd4\u5982\u4ece\u7f51\u9875\u6e90\u4ee3\u7801\u4e2d\u63d0\u53d6\u6240\u6709\u7684\u8d85\u94fe\u63a5\u5730\u5740\u7b49\u3002<\/p>\n<h2>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u573a\u666f<\/h2>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u6587\u672c\u641c\u7d22\u548c\u66ff\u6362<\/h4>\n<p>\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5feb\u901f\u67e5\u627e\u7279\u5b9a\u6a21\u5f0f\u7684\u6587\u672c\uff0c\u5e76\u8fdb\u884c\u66ff\u6362\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5c06\u6240\u6709\u5305\u542b \u201cabc\u201d \u7684\u5b57\u7b26\u4e32\u66ff\u6362\u4e3a \u201cdef\u201d\u3002<\/p>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u6570\u636e\u9a8c\u8bc1<\/h4>\n<p>\u5728\u8868\u5355\u9a8c\u8bc1\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u6765\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684\u90ae\u7bb1\u5730\u5740\u3001\u7535\u8bdd\u53f7\u7801\u3001\u5bc6\u7801\u7b49\u662f\u5426\u7b26\u5408\u7279\u5b9a\u7684\u683c\u5f0f\u8981\u6c42\u3002<\/p>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u65e5\u5fd7\u5206\u6790<\/h4>\n<p>\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u4ece\u5927\u91cf\u7684\u65e5\u5fd7\u6587\u4ef6\u4e2d\u63d0\u53d6\u51fa\u6709\u7528\u7684\u4fe1\u606f\uff0c\u5982\u7279\u5b9a\u7684\u9519\u8bef\u6d88\u606f\u3001\u8bbf\u95ee IP \u5730\u5740\u7b49\u3002<\/p>\n<h4 class=\"auto-hide-last-sibling-br paragraph-u1TS5p paragraph-element br-paragraph-space\">\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5e94\u7528<\/h4>\n<p>\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u90fd\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5982 Python\u3001Java\u3001JavaScript \u7b49\u3002\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5904\u7406\u6587\u672c\u6570\u636e\u3002<\/p>\n<h1>2.\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b<\/h1>\n<p data-spm-anchor-id=\"5176.28103460.0.i16.5e045d272koQX4\">\u6b63\u5219\u8868\u8fbe\u5f0f\uff08Regular Expression, \u7b80\u79f0 regex \u6216 regexp\uff09\u548c\u901a\u914d\u7b26\uff08wildcard\uff09\u90fd\u662f\u7528\u4e8e\u6a21\u5f0f\u5339\u914d\u7684\u5de5\u5177\uff0c\u4f46\u5b83\u4eec\u5728\u529f\u80fd\u3001\u8bed\u6cd5\u548c\u4f7f\u7528\u573a\u666f\u4e0a\u6709\u663e\u8457\u7684\u533a\u522b\u3002\u4e0b\u9762\u8be6\u7ec6\u5bf9\u6bd4\u8fd9\u4e24\u79cd\u6a21\u5f0f\u5339\u914d\u5de5\u5177<\/p>\n<h2>\u6b63\u5219\u8868\u8fbe\u5f0f<\/h2>\n<h4>\u529f\u80fd\u5f3a\u5927<\/h4>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u975e\u5e38\u590d\u6742\u7684\u6587\u672c\u5339\u914d\u3001\u67e5\u627e\u3001\u66ff\u6362\u7b49\u64cd\u4f5c\u3002\u5b83\u652f\u6301\u5404\u79cd\u5b57\u7b26\u7c7b\u3001\u91cf\u8bcd\u3001\u65ad\u8a00\u7b49\u9ad8\u7ea7\u7279\u6027\u3002<\/p>\n<h4>\u7075\u6d3b\u6027\u9ad8<\/h4>\n<p>\u53ef\u4ee5\u7528\u6765\u5339\u914d\u590d\u6742\u7684\u6a21\u5f0f\uff0c\u5982\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3001\u7535\u8bdd\u53f7\u7801\u3001URL\u7b49\u3002<\/p>\n<h4>\u5e7f\u6cdb\u4f7f\u7528<\/h4>\n<p>\u51e0\u4e4e\u6240\u6709\u7684\u7f16\u7a0b\u8bed\u8a00\u90fd\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u4f7f\u7528\uff0c\u5b83\u5728\u6587\u672c\u5904\u7406\u3001\u6570\u636e\u9a8c\u8bc1\u7b49\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<h2>\u901a\u914d\u7b26<\/h2>\n<h4>\u7b80\u5355\u76f4\u89c2<\/h4>\n<p>\u901a\u914d\u7b26\u901a\u5e38\u53ea\u5305\u542b\u6709\u9650\u7684\u51e0\u4e2a\u7b26\u53f7\uff0c\u5982\u661f\u53f7(<code>*<\/code>)\u4ee3\u8868\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\uff0c\u95ee\u53f7(<code>?<\/code>)\u4ee3\u8868\u5355\u4e2a\u5b57\u7b26\uff0c\u8fd9\u4e9b\u7b26\u53f7\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002<\/p>\n<h4>\u7279\u5b9a\u7528\u9014<\/h4>\n<p>\u901a\u914d\u7b26\u4e3b\u8981\u7528\u4e8e\u6587\u4ef6\u540d\u5339\u914d\uff0c\u5728\u547d\u4ee4\u884c\u754c\u9762\uff08\u5982DOS\u3001Unix\/Linux shell\uff09\u4e2d\u5e38\u89c1\uff0c\u7528\u4e8e\u6307\u5b9a\u4e00\u7ec4\u6587\u4ef6\u540d\u3002<\/p>\n<h4>\u8bed\u6cd5\u7b80\u5355<\/h4>\n<p>\u7531\u4e8e\u529f\u80fd\u8f83\u4e3a\u5355\u4e00\uff0c\u901a\u914d\u7b26\u7684\u8bed\u6cd5\u4e5f\u76f8\u5bf9\u7b80\u5355\uff0c\u5bb9\u6613\u4e0a\u624b\u3002<\/p>\n<h2>\u8bed\u6cd5<\/h2>\n<p><a href=\"https:\/\/www.qiangzhenshuai.com\/?attachment_id=1369\" rel=\"attachment wp-att-1369\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1369\" src=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2024\/11\/\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b.png?resize=640%2C403&#038;ssl=1\" alt=\"\" width=\"640\" height=\"403\" srcset=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2024\/11\/\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b.png?w=1177&amp;ssl=1 1177w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2024\/11\/\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b.png?resize=300%2C189&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2024\/11\/\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b.png?resize=1024%2C646&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2024\/11\/\u6b63\u5219\u548c\u901a\u914d\u7b26\u533a\u522b.png?resize=768%2C484&amp;ssl=1 768w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<h4>\u6b63\u5219\u8868\u8fbe\u5f0f<\/h4>\n<h4><strong>\u5b57\u7b26\u7c7b<\/strong><\/h4>\n<p>[abc]\u00a0\u5339\u914d\u00a0a\u3001b\u00a0\u6216\u00a0c\u00a0\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>[a-z]\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u3002<\/p>\n<p>[0-9]\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<p>\u9884\u5b9a\u4e49\u5b57\u7b26\u7c7b\uff1a<\/p>\n<p>\\d\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<p>\\w\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u3002<\/p>\n<p>\\s\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u7a7a\u767d\u5b57\u7b26\u3002<\/p>\n<p>\u91cf\u8bcd\uff1a<\/p>\n<p>*\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u96f6\u6b21\u6216\u591a\u6b21\u3002<\/p>\n<p>+\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u4e00\u6b21\u6216\u591a\u6b21\u3002<\/p>\n<p>?\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u96f6\u6b21\u6216\u4e00\u6b21\u3002<\/p>\n<p>{n}\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u6070\u597d n \u6b21\u3002<\/p>\n<p>{n,}\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u81f3\u5c11 n \u6b21\u3002<\/p>\n<p>{n,m}\u00a0\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u81f3\u5c11 n \u6b21\uff0c\u81f3\u591a m \u6b21\u3002<\/p>\n<p>\u5b9a\u4f4d\u7b26<\/p>\n<p>^\u00a0\u5339\u914d\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u3002<\/p>\n<p>$\u00a0\u5339\u914d\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u3002<\/p>\n<p>\\b\u00a0\u5339\u914d\u5355\u8bcd\u8fb9\u754c\u3002<\/p>\n<p>\\B\u00a0\u5339\u914d\u975e\u5355\u8bcd\u8fb9\u754c\u3002<\/p>\n<p>\u5206\u7ec4\u548c\u5f15\u7528<\/p>\n<p>()\u00a0\u7528\u4e8e\u5206\u7ec4\u3002<\/p>\n<p>\\1,\u00a0\\2, &#8230; \u7528\u4e8e\u5f15\u7528\u524d\u9762\u7684\u5206\u7ec4\u3002<\/p>\n<p>\u9009\u62e9\uff1a<\/p>\n<p>|\u00a0\u8868\u793a\u201c\u6216\u201d\uff0c\u5339\u914d\u5de6\u8fb9\u6216\u53f3\u8fb9\u7684\u8868\u8fbe\u5f0f\u3002<\/p>\n<h4>\u901a\u914d\u7b26<\/h4>\n<p>\u661f\u53f7 (*)\uff1a\u5339\u914d\u4efb\u610f\u6570\u91cf\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<p>\u95ee\u53f7 (?)\uff1a\u5339\u914d\u5355\u4e2a\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<p>\u65b9\u62ec\u53f7 ([])\uff1a\u5339\u914d\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>[abc]\u00a0\u5339\u914d\u00a0a\u3001b\u00a0\u6216\u00a0c\u00a0\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>[a-z]\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\u3002<\/p>\n<p>[0-9]\u00a0\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<p>\u8303\u56f4\u548c\u5426\u5b9a\uff1a<\/p>\n<p>[^abc]\u00a0\u5339\u914d\u9664\u00a0a\u3001b\u3001c\u00a0\u4e4b\u5916\u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/p>\n<p>[!abc]\u00a0\u540c\u4e0a\uff0c\u67d0\u4e9b\u7cfb\u7edf\u4e2d\u4f7f\u7528\u00a0!\u00a0\u8868\u793a\u5426\u5b9a\u3002<\/p>\n<h2>\u4f7f\u7528\u573a\u666f<\/h2>\n<h4>\u6b63\u5219\u8868\u8fbe\u5f0f<\/h4>\n<p>\u6587\u672c\u5904\u7406\uff1a\u5728\u7f16\u7a0b\u4e2d\u5bf9\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u8fdb\u884c\u683c\u5f0f\u6821\u9a8c\uff0c\u5982\u9a8c\u8bc1\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3001\u7535\u8bdd\u53f7\u7801\u7b49\u3002<\/p>\n<p>\u641c\u7d22\u548c\u66ff\u6362\uff1a\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u8fdb\u884c\u590d\u6742\u7684\u641c\u7d22\u548c\u66ff\u6362\u64cd\u4f5c\u3002<\/p>\n<p>\u6570\u636e\u63d0\u53d6\uff1a\u4ece\u65e5\u5fd7\u6587\u4ef6\u6216\u5176\u4ed6\u6587\u672c\u6570\u636e\u4e2d\u63d0\u53d6\u7279\u5b9a\u4fe1\u606f\u3002<\/p>\n<h4>\u901a\u914d\u7b26<\/h4>\n<p>\u6587\u4ef6\u540d\u5339\u914d\uff1a\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e2d\u7528\u4e8e\u6307\u5b9a\u4e00\u7ec4\u6587\u4ef6\u540d\uff0c\u5982\u00a0*.txt\u00a0\u5339\u914d\u6240\u6709\u6269\u5c55\u540d\u4e3a\u00a0.txt\u00a0\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u8def\u5f84\u5339\u914d\uff1a\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7528\u4e8e\u5339\u914d\u76ee\u5f55\u8def\u5f84\uff0c\u5982\u00a0*.\/*\/*.jpg\u00a0\u5339\u914d\u6240\u6709\u5b50\u76ee\u5f55\u4e2d\u7684\u00a0.jpg\u00a0\u6587\u4ef6\u3002<\/p>\n<h3 class=\"header-o0Xpoc auto-hide-last-sibling-br\">\u5339\u914d\u7cbe\u5ea6<\/h3>\n<p><strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\uff1a<\/p>\n<p>\u80fd\u5b9e\u73b0\u9ad8\u5ea6\u7cbe\u786e\u5339\u914d\u3002\u53ef\u5bf9\u6587\u672c\u4e2d\u5b57\u7b26\u4f4d\u7f6e\u3001\u51fa\u73b0\u6b21\u6570\u3001\u7ec4\u5408\u65b9\u5f0f\u7b49\u8fdb\u884c\u7ec6\u81f4\u89c4\u5b9a\u3002<\/p>\n<p>\u4e0d\u4ec5\u80fd\u5339\u914d\u5b57\u7b26\u672c\u8eab\uff0c\u8fd8\u80fd\u5339\u914d\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u5982\u4ee5\u67d0\u7279\u5b9a\u5b57\u7b26\u4e32\u5f00\u5934\u4e14\u4ee5\u53e6\u4e00\u7279\u5b9a\u5b57\u7b26\u4e32\u7ed3\u5c3e\uff0c\u4e2d\u95f4\u542b\u7279\u5b9a\u683c\u5f0f\u5b57\u7b26\u7684\u6587\u672c\u7b49\u590d\u6742\u60c5\u51b5\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u201c\\d {3}-\\d {3}-\\d {4}\u201d \u53ef\u7cbe\u786e\u5339\u914d\u7f8e\u56fd\u7535\u8bdd\u53f7\u7801\u683c\u5f0f\uff08\u4e09\u4e2a\u6570\u5b57 &#8211; \u4e09\u4e2a\u6570\u5b57 &#8211; \u56db\u4e2a\u6570\u5b57\uff09\uff0c\u901a\u8fc7\u91cf\u8bcd \u201c{n}\u201d \u7cbe\u51c6\u9650\u5b9a\u6570\u5b57\u51fa\u73b0\u6b21\u6570\u3002<\/p>\n<p><strong>\u901a\u914d\u7b26<\/strong>\uff1a<\/p>\n<p>\u5339\u914d\u8f83\u4e3a\u7c97\u653e\u3002\u4e3b\u8981\u4fa7\u91cd\u4e8e\u5bf9\u6587\u4ef6\u540d\u3001\u7b80\u5355\u6587\u672c\u7247\u6bb5\u7b49\u8fdb\u884c\u57fa\u4e8e\u5b57\u7b26\u6570\u91cf\u548c\u7c7b\u578b\u7684\u5927\u81f4\u5339\u914d\u3002<\/p>\n<p>\u6bd4\u5982\u5728\u6587\u4ef6\u7cfb\u7edf\u641c\u7d22\u4e2d\uff0c\u901a\u914d\u7b26\u53ef\u5feb\u901f\u627e\u5230\u7b26\u5408\u6269\u5c55\u540d\u6216\u6587\u4ef6\u540d\u90e8\u5206\u5927\u81f4\u7279\u5f81\u7684\u6587\u4ef6\uff0c\u4f46\u96be\u4ee5\u50cf\u6b63\u5219\u8868\u8fbe\u5f0f\u90a3\u6837\u5bf9\u6587\u4ef6\u5185\u5bb9\u4e2d\u590d\u6742\u6587\u672c\u6a21\u5f0f\u8fdb\u884c\u7cbe\u7ec6\u5339\u914d\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u201c*.jpg\u201d \u53ef\u627e\u5230\u6240\u6709\u4ee5 \u201c.jpg\u201d \u4e3a\u6269\u5c55\u540d\u7684\u6587\u4ef6\uff0c\u4f46\u65e0\u6cd5\u786e\u5b9a\u6587\u4ef6\u5185\u5bb9\u4e2d\u662f\u5426\u5b58\u5728\u7279\u5b9a\u683c\u5f0f\u7684\u6587\u672c\u3002<\/p>\n<h1>3.perl\u6b63\u5219<\/h1>\n<p>Perl\u8bed\u8a00\u4ee5\u5176\u5f3a\u5927\u7684\u6587\u672c\u5904\u7406\u80fd\u529b\u800c\u95fb\u540d\uff0c\u5176\u4e2d\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u5176\u6838\u5fc3\u7279\u6027\u4e4b\u4e00\u3002Perl\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u57fa\u672c\u4e0a\u662f\u5e38\u7528\u8bed\u8a00\u4e2d\u6700\u5f3a\u5927\u7684\uff0c\u5f88\u591a\u8bed\u8a00\u8bbe\u8ba1\u6b63\u5219\u5f0f\u652f\u6301\u7684\u65f6\u5019\u90fd\u53c2\u8003Perl\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002Perl\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\u4e09\u79cd\u5f62\u5f0f\uff0c\u5206\u522b\u662f\u5339\u914d\u3001\u66ff\u6362\u548c\u8f6c\u5316<\/p>\n<h2>\u57fa\u672c\u8bed\u6cd5<\/h2>\n<p>\u5728 Perl \u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u901a\u5e38\u7528 m\/\/ \u8fdb\u884c\u5339\u914d\uff0c\u7528 s\/\/\/ \u8fdb\u884c\u66ff\u6362\u3002\u5982\u679c\u4e0d\u6307\u5b9a m\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 \/\/ \u8fdb\u884c\u5339\u914d<\/p>\n<h2>\u5e38\u7528\u5b57\u7b26<\/h2>\n<p>\u70b9\u00a0.\uff1a\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\uff08\u9664\u4e86\u6362\u884c\u7b26\uff09\u3002<br \/>\n\u661f\u53f7\u00a0*\uff1a\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26\u96f6\u6b21\u6216\u591a\u6b21\u3002<br \/>\n\u52a0\u53f7\u00a0+\uff1a\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21\u3002<br \/>\n\u95ee\u53f7\u00a0?\uff1a\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26\u96f6\u6b21\u6216\u4e00\u6b21\u3002<br \/>\n\u82b1\u62ec\u53f7\u00a0{}\uff1a\u6307\u5b9a\u524d\u4e00\u4e2a\u5b57\u7b26\u7684\u51fa\u73b0\u6b21\u6570\u3002<br \/>\n\u65b9\u62ec\u53f7\u00a0[]\uff1a\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u7c7b\u3002<br \/>\n\u8131\u5b57\u7b26\u00a0^\uff1a\u5339\u914d\u884c\u9996\u6216\u5426\u5b9a\u5b57\u7b26\u7c7b\u3002<br \/>\n\u7f8e\u5143\u7b26\u53f7\u00a0$\uff1a\u5339\u914d\u884c\u5c3e\u3002<br \/>\n\u7ad6\u7ebf\u00a0|\uff1a\u903b\u8f91\u6216\u3002<br \/>\n\u5706\u62ec\u53f7\u00a0()\uff1a\u5206\u7ec4\u548c\u6355\u83b7<\/p>\n<p>i \u5ffd\u7565\u6a21\u5f0f\u4e2d\u7684\u5927\u5c0f\u5199<br \/>\nm \u591a\u884c\u6a21\u5f0f<br \/>\no \u4ec5\u8d4b\u503c\u4e00\u6b21<br \/>\ns \u5355\u884c\u6a21\u5f0f\uff0c&#8221;.&#8221; \u5339\u914d &#8220;\\n&#8221;\uff08\u9ed8\u8ba4\u4e0d\u5339\u914d\uff09<br \/>\nx \u5ffd\u7565\u6a21\u5f0f\u4e2d\u7684\u7a7a\u767d<br \/>\ng \u5168\u5c40\u5339\u914d<br \/>\ncg \u5168\u5c40\u5339\u914d\u5931\u8d25\u540e\uff0c\u5141\u8bb8\u518d\u6b21\u67e5\u627e\u5339\u914d\u4e32<\/p>\n<h4 id=\"3. \u6b63\u5219\u8868\u8fbe\u5f0f\u53d8\u91cf\" data-line=\"38\">\u6b63\u5219\u8868\u8fbe\u5f0f\u53d8\u91cf<\/h4>\n<p data-line=\"39\">Perl\u5904\u7406\u5b8c\u540e\u4f1a\u7ed9\u5339\u914d\u5230\u7684\u503c\u5b58\u5728\u4e09\u4e2a\u7279\u6b8a\u53d8\u91cf\u540d\uff1a<\/p>\n<p>$\uff1a\u5339\u914d\u90e8\u5206\u7684\u524d\u4e00\u90e8\u5206\u5b57\u7b26\u4e32<br \/>\n$&amp;\uff1a\u5339\u914d\u7684\u5b57\u7b26\u4e32<br \/>\n$&#8217;\uff1a\u8fd8\u6ca1\u6709\u5339\u914d\u7684\u5269\u4f59\u5b57\u7b26\u4e32<\/p>\n<h2 data-line=\"135\">Perl\u4e2d\u7684\u4fee\u9970\u7b26\u5206\u4e3a\u4e24\u5927\u7c7b\uff1a\u6a21\u5f0f\u4fee\u9970\u7b26\u548c\u5339\u914d\u4fee\u9970\u7b26\u3002<\/h2>\n<h3 data-line=\"137\">\u6a21\u5f0f\u4fee\u9970\u7b26<\/h3>\n<p>\/i\uff1a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u8fdb\u884c\u5339\u914d\u3002<br \/>\n\/m\uff1a\u591a\u884c\u5339\u914d\uff0c\u4f7f\u5f97\u00a0^\u00a0\u548c\u00a0$\u00a0\u5339\u914d\u6bcf\u4e00\u884c\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u3002<br \/>\n\/s\uff1a\u5355\u884c\u5339\u914d\uff0c\u4f7f\u5f97\u70b9\u53f7\u00a0.\u00a0\u5339\u914d\u6240\u6709\u5b57\u7b26\uff0c\u5305\u62ec\u6362\u884c\u7b26\u3002<br \/>\n\/x\uff1a\u6269\u5c55\u6a21\u5f0f\uff0c\u5141\u8bb8\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u52a0\u5165\u7a7a\u683c\u548c\u6ce8\u91ca\uff0c\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/p>\n<h3 data-line=\"143\">\u5339\u914d\u4fee\u9970\u7b26<\/h3>\n<p>\/g\uff1a\u5168\u5c40\u5339\u914d\uff0c\u627e\u5230\u6240\u6709\u5339\u914d\u9879\uff0c\u800c\u4e0d\u662f\u4ec5\u7b2c\u4e00\u4e2a\u3002<br \/>\n\/c\uff1a\u5339\u914d\u65f6\u4e0d\u6355\u83b7\u5206\u7ec4\uff0c\u63d0\u9ad8\u6548\u7387\u3002<br \/>\n\/l\uff1a\u4ece\u5339\u914d\u7ed3\u679c\u4e2d\u5220\u9664\u53cd\u5411\u5f15\u7528\u3002<br \/>\n\/p\uff1a\u6267\u884c\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u4fdd\u7559\u6700\u540e\u7684\u5339\u914d\u7ed3\u679c\u3002<\/p>\n<h3>\u96f6\u5bbd\u65ad\u8a00<\/h3>\n<p>(?=&#8230;)\uff1a\u6b63\u5411\u80af\u5b9a\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u5339\u914d\u00a0&#8230;\u00a0\u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u3002<br \/>\n(?!&#8230;)\uff1a\u6b63\u5411\u5426\u5b9a\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u4e0d\u5339\u914d\u00a0&#8230;\u00a0\u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u3002<br \/>\n(?&lt;=&#8230;)\uff1a\u53cd\u5411\u80af\u5b9a\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u5339\u914d\u00a0&#8230;\u00a0\u7684\u5b57\u7b26\u4e32\u7ed3\u675f\u5904\u5339\u914d\u3002<br \/>\n(?&lt;!&#8230;)\uff1a\u53cd\u5411\u5426\u5b9a\u9884\u67e5\uff0c\u5728\u4efb\u4f55\u4e0d\u5339\u914d\u00a0&#8230;\u00a0\u7684\u5b57\u7b26\u4e32\u7ed3\u675f\u5904\u5339\u914d\u3002<\/p>\n<h2>\u793a\u4f8b<\/h2>\n<h4>1<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl.sh<br \/>\n#!\/usr\/bin\/perl<br \/>\n$bar = &#8220;I am runoob site. welcome to runoob site.&#8221;;<br \/>\nif ($bar =~ \/run\/) {<br \/>\nprint &#8220;\u7b2c\u4e00\u6b21\u5339\u914d\\n&#8221;;<br \/>\n} else {<br \/>\nprint &#8220;\u7b2c\u4e00\u6b21\u4e0d\u5339\u914d\\n&#8221;;<br \/>\n}<br \/>\n$bar = &#8220;run&#8221;;<br \/>\nif ($bar =~ \/run\/) {<br \/>\nprint &#8220;\u7b2c\u4e8c\u6b21\u5339\u914d\\n&#8221;;<br \/>\n} else {<br \/>\nprint &#8220;\u7b2c\u4e8c\u6b21\u4e0d\u5339\u914d\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl.sh<br \/>\n\u7b2c\u4e00\u6b21\u5339\u914d<br \/>\n\u7b2c\u4e8c\u6b21\u5339\u914d<\/p>\n<h4>2<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl1.sh<br \/>\n#!\/usr\/bin\/perl<br \/>\nuse strict;<br \/>\nuse warnings;<\/p>\n<p>my $text = &#8220;The quick brown fox jumps over the lazy dog.&#8221;;<\/p>\n<p># \u6b63\u5411\u80af\u5b9a\u9884\u67e5<br \/>\nif ($text =~ \/fox(?= jumps)\/) {<br \/>\nprint &#8220;Found &#8216;fox&#8217; followed by &#8216;jumps&#8217;.\\n&#8221;;<br \/>\n}<\/p>\n<p># \u6b63\u5411\u5426\u5b9a\u9884\u67e5<br \/>\nif ($text =~ \/fox(?! jumps)\/) {<br \/>\nprint &#8220;Found &#8216;fox&#8217; not followed by &#8216;jumps&#8217;.\\n&#8221;;<br \/>\n}<\/p>\n<p># \u53cd\u5411\u80af\u5b9a\u9884\u67e5<br \/>\nif ($text =~ \/(?&lt;=The )quick\/) {<br \/>\nprint &#8220;Found &#8216;quick&#8217; preceded by &#8216;The &#8216;.\\n&#8221;;<br \/>\n}<\/p>\n<p># \u53cd\u5411\u5426\u5b9a\u9884\u67e5<br \/>\nif ($text =~ \/(?&lt;!The )quick\/) {<br \/>\nprint &#8220;Found &#8216;quick&#8217; not preceded by &#8216;The &#8216;.\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl1.sh<br \/>\nFound &#8216;fox&#8217; followed by &#8216;jumps&#8217;.<br \/>\nFound &#8216;quick&#8217; preceded by &#8216;The &#8216;.<\/p>\n<h4>3.\u975e\u6355\u83b7\u7ec4\uff1a\u7528\u4e8e\u5e94\u7528\u91cf\u8bcd\uff0c\u4f46\u4e0d\u5b58\u50a8\u5339\u914d\u7684\u6587\u672c<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl2.sh<br \/>\n$text = &#8220;The year 2023 is not far away.&#8221;;<br \/>\n@matches = ($text =~ \/(?:\\d+)\/g);<br \/>\nprint &#8220;Year found: @matches\\n&#8221;;<br \/>\n[root@shell \/server\/scripts]$ perl perl2.sh<br \/>\nYear found: 2023<\/p>\n<h4>4.\u540e\u5411\u548c\u524d\u5411\u65ad\u8a00\uff1a\u65ad\u8a00\u5141\u8bb8\u60a8\u6307\u5b9a\u5fc5\u987b\u5728\u5b57\u7b26\u4e32\u7684\u67d0\u4e2a\u4f4d\u7f6e\u4e4b\u524d\u6216\u4e4b\u540e\u7684\u6761\u4ef6\uff0c\u4f46\u4e0d\u4f1a\u6d88\u8017\u5b57\u7b26<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl3.sh<br \/>\n$text = &#8220;We have 2 apples and 3 bananas.&#8221;;<br \/>\nif ($text =~ \/(\\d+) apples\/) {<br \/>\nprint &#8220;We have &#8220;. $1. &#8221; apples.\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl3.sh<br \/>\nWe have 2 apples.<\/p>\n<h4>5.\u6b63\u5411\u540e\u77bb\uff1a\u5141\u8bb8\u60a8\u6307\u5b9a\u67d0\u4e2a\u6a21\u5f0f\u540e\u9762\u5fc5\u987b\u8ddf\u968f\u7684\u53e6\u4e00\u4e2a\u6a21\u5f0f<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl4.sh<br \/>\n$text = &#8220;Please press F5 to refresh.&#8221;;<br \/>\nif ($text =~ \/(F5)(?= to refresh)\/) {<br \/>\nprint &#8220;Press &#8220;. $1. &#8221; to refresh.\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl4.sh<br \/>\nPress F5 to refresh.<\/p>\n<h4>6.\u8d1f\u5411\u5148\u884c\u65ad\u8a00\uff1a\u7528\u4e8e\u6307\u5b9a\u67d0\u4e2a\u6a21\u5f0f\u524d\u9762\u4e0d\u80fd\u51fa\u73b0\u7684\u6a21\u5f0f<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl5.sh<br \/>\n$text = &#8220;Do not press F12.&#8221;;<br \/>\nif ($text =~ \/(F12)(?! to refresh)\/) {<br \/>\nprint &#8220;Do not press &#8220;. $1. &#8220;.\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl5.sh<br \/>\nDo not press F12.<\/p>\n<h4>7.\u4f7f\u7528lookbehind\u8fdb\u884c\u65ad\u8a00\uff1a\u5141\u8bb8\u4f60\u5728\u5b57\u7b26\u4e32\u4e2d\u5411\u524d\u67e5\u770b\uff0c\u786e\u4fdd\u67d0\u4e2a\u6a21\u5f0f\u4e4b\u524d\u4e0d\u51fa\u73b0<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl6.sh<br \/>\n$text = &#8220;The date is 12\/31\/2023.&#8221;;<br \/>\nif ($text =~ \/(?&lt;!\\w)(\\d{1,2}\\\/\\d{1,2}\\\/\\d{4})\/) {<br \/>\nprint &#8220;Date found: $1\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl6.sh<br \/>\nDate found: 12\/31\/2023<\/p>\n<h4>8.\u5047\u8bbe\u6211\u4eec\u60f3\u627e\u5230\u6240\u6709\u4e0d\u5728\u5355\u8bcd\u5185\u90e8\u7684 &#8220;q&#8221;<\/h4>\n<p>[root@shell \/server\/scripts]$ cat perl7.sh<br \/>\n#!\/usr\/bin\/perl<br \/>\nuse strict;<br \/>\nuse warnings;<\/p>\n<p>my $text = &#8220;The quick brown fox jumps over the lazy dog.&#8221;;<\/p>\n<p># \u4f7f\u7528\u8d1f\u5411\u540e\u77bb\u65ad\u8a00\u627e\u5230\u4e0d\u5728\u5355\u8bcd\u5185\u90e8\u7684 &#8220;q&#8221;<br \/>\nwhile ($text =~ \/(?&lt;!\\w)q\/g) {<br \/>\nprint &#8220;Found &#8216;q&#8217; not preceded by a word character at position: &#8220;, pos($text), &#8220;\\n&#8221;;<br \/>\n}<br \/>\n[root@shell \/server\/scripts]$ perl perl7.sh<br \/>\nFound &#8216;q&#8217; not preceded by a word character at position: 5<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u6b63\u5219\u8868\u8fbe\u5f0f\u6982\u8ff0 \u6b63\u5219\u8868\u8fbe\u5f0f\uff08Regular Expression\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u5339\u914d\u3001\u67e5\u627e\u548c\u66ff\u6362\u6587\u672c\u4e2d\u7279\u5b9a\u6a21\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[5],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1368"}],"collection":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1368"}],"version-history":[{"count":4,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1368\/revisions"}],"predecessor-version":[{"id":1375,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1368\/revisions\/1375"}],"wp:attachment":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}